﻿
using KingerRobot.MexicoSailunMDC.Dao;
using KingerRobot.MexicoSailunWMS.Spi;
using System.Collections;

//using MyBatis.DataMapper.TypeHandlers;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Net;
using System.Reflection.Emit;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace KingerRobot.MexicoSailunWMS.SpiService;

public class BMonitorManage : IMonitorManage
{
    private static List<LineMonitorBeans> _TotalCacheMonitorBeans;

    private static List<LineMonitorBeans> _CacheMonitorBeans;

    private static DateTime _BeyondTime = DateTime.MinValue;

    private static readonly IWmsSetting _WmsSetting = new BWmsSetting();

    private static readonly IRcsEquipWarehouse _RcsEquipWarehouse = new BRcsEquipWarehouse();
    private static readonly IProdMaterial _ProdMaterial = new BProdMaterial();

    #region 线体监控部分
    public List<LineMonitorBeans> GetLineMonitorBeansV2()
    {
        if (_BeyondTime > DateTime.MinValue && DateTime.Now < _BeyondTime && _TotalCacheMonitorBeans is not null && _TotalCacheMonitorBeans.Any())
        {

            //if (param.IsFirstTime is not null && (bool)param.IsFirstTime)
            //{
            //    return _TotalCacheMonitorBeans;
            //}

            //if ((_CacheMonitorBeans is not null && _CacheMonitorBeans.Any()))
            //{
            //    //WriteLog("取缓存数据", true);
            //    return _CacheMonitorBeans;
            //}
            //return null;

        }
        //WriteLog("未取缓存数据", true);
        //VExceptEquipNode
        var list1 = Task.Run(() => GetExceptEquipNode());//获取线体上节点的
        //VEquipCrnFolkNode
        var list2 = Task.Run(() => GetEquipCrnFolkNode());
        //VEquipEMSNode
        var list3 = Task.Run(() => GetEquipEMSNode());
        //VEquipCrnNode
        var list4 = Task.Run(() => GetEquipCrnNode());

        //var list5 = Task.Run(() => GetEquipBuildingNode());

        //var list6 = Task.Run(() => null);


        var list7 = list1.Result.Union(list2.Result).Union(list3.Result).Union(list4.Result).ToList();
        //var list6 = list1.Result.Union(list2.Result).Union(list3.Result).Union(list4.Result).Union(list5.Result).ToList();
        //_BeyondTime = DateTime.Now.AddSeconds(4);

        //var list = new List<LineMonitorBeans>();

        //if (_TotalCacheMonitorBeans is not null && _TotalCacheMonitorBeans.Any())
        //{
        //    list = list7.Join(_TotalCacheMonitorBeans, f => f.Id, s => s.Id, (f, s) => new { List1 = f, List2 = s })
        //    .Where(f => f.List1.TaskNo != f.List2.TaskNo).Select(f => f.List1).ToList();
        //}


        //_TotalCacheMonitorBeans = list7;

        //_CacheMonitorBeans = list;

        //if (param.IsFirstTime is not null && !(bool)param.IsFirstTime)
        //{
        //    return list;
        //}
        return list7;
    }

    public List<LineMonitorBeans> GetLineMonitorBeansV3()
    {
        var list2 = GetCuringNodes();
        return list2;
    }

    public List<LineMonitorBeans> GetLineMonitorBeansNew()
    {

        var list1 = Task.Run(() => GetExceptEquipNodeV2());//获取线体上节点的
        //VEquipCrnFolkNode
        var list2 = Task.Run(() => GetCuringNodes());
        //VEquipEMSNode
        var list3 = Task.Run(() => GetEquipEMSNodeV2());
        //VEquipCrnNode
        var list4 = Task.Run(() => GetEquipCrnNodeV2());
        var list5 = Task.Run(() => GetEquipElementNode());


        var list6 = list1.Result.Union(list2.Result).Union(list3.Result).Union(list4.Result).Union(list5.Result).ToList();
        ////_BeyondTime = DateTime.Now.AddSeconds(4);

        ////var list = new List<LineMonitorBeans>();

        ////if (_TotalCacheMonitorBeans is not null && _TotalCacheMonitorBeans.Any())
        ////{
        ////    list = list7.Join(_TotalCacheMonitorBeans, f => f.Id, s => s.Id, (f, s) => new { List1 = f, List2 = s })
        ////    .Where(f => f.List1.TaskNo != f.List2.TaskNo).Select(f => f.List1).ToList();
        ////}


        ////_TotalCacheMonitorBeans = list7;

        ////_CacheMonitorBeans = list;

        ////if (param.IsFirstTime is not null && !(bool)param.IsFirstTime)
        ////{
        ////    return list;
        ////}
        return list6;
    }

    public List<LineMonitorBeans> GetLineMonitorBeans(LineMonitorParam param)
    {

        // return null;
        //return Caching.GetData("GetLineMonitorBeans", 4, () =>
        //{

        //return new List<LineMonitorBeans>();

        var list1 = Task.Run(() => GetExceptEquipNode());//获取线体上节点的

        var list2 = Task.Run(() => GetEquipCrnFolkNode());

        var list3 = Task.Run(() => GetEquipEMSNode());

        var list4 = Task.Run(() => GetEquipCrnNode());

        var list5 = Task.Run(() => GetEquipBuildingNode());
        var list6 = list1.Result.Union(list2.Result).Union(list3.Result).Union(list4.Result).Union(list5.Result).ToList();
        ////WriteLog($"list6{list6.ToJson()}", true);


        return list6;
        //});
    }

    public List<POVLocationEnableNum> GetRcsLocation()
    {

        var db = Db.Default;
        return db.VLocationEnableNum.ToList();
    }

    //public List<TemAndHumBeans> GetTemperatureAndHumidity()
    //{
    //    var db = Db.Default;
    //    var allTemperatureAndHumidity = db.WmsHumidityDatass.GroupBy(x => x.EquipId).Select(t => new
    //    {
    //        EquipId = t.Key,
    //        Temperature = t.OrderByDescending(t => t.CreateTime).Select(t => t.Temperature).FirstOrDefault(),
    //        Humidity = t.OrderByDescending(t => t.CreateTime).Select(t => t.Humidity).FirstOrDefault(),
    //    }).ToList();

    //    //车间温度值 低于此数值显示绿色，高于显示红色
    //    _ = decimal.TryParse(_WmsSetting.GetWmsSettingByCode(ConstFields.Temperature).Value, out var settingTemperature);
    //    //车间温湿度值 低于此数值显示绿色，高于显示红色
    //    _ = decimal.TryParse(_WmsSetting.GetWmsSettingByCode(ConstFields.Humidity).Value, out var settingHumidity);

    //    List<TemAndHumBeans> temAndHumBeanLists = new List<TemAndHumBeans>();
    //    var temperatureColor = "#FFF8DC";
    //    var humidityColor = "#FFF8DC";


    //    foreach (var aTemperatureAndHumidity in allTemperatureAndHumidity)
    //    {
    //        var temAndHumBean = new TemAndHumBeans();

    //        if (aTemperatureAndHumidity.Temperature > settingTemperature)
    //        {
    //            temperatureColor = "#F43308";
    //        }
    //        else
    //        {
    //            temperatureColor = "#009100";
    //        }
    //        if (aTemperatureAndHumidity.Humidity > settingHumidity)
    //        {
    //            humidityColor = "#F43308";
    //        }
    //        else
    //        {
    //            humidityColor = "#009100";
    //        }

    //        temAndHumBean.EquipId = aTemperatureAndHumidity.EquipId;
    //        temAndHumBean.Temperature = (double)aTemperatureAndHumidity.Temperature;
    //        temAndHumBean.Humidity = (double)aTemperatureAndHumidity.Humidity;
    //        temAndHumBean.TemperColor = temperatureColor;
    //        temAndHumBean.HumColor = humidityColor;
    //        temAndHumBeanLists.Add(temAndHumBean);
    //    }


    //    return temAndHumBeanLists;
    //}



    /// <summary>
    /// 获取能从线体读取任务号的和不会有任务号的节点
    /// </summary>
    /// <returns></returns>
    public List<LineMonitorBeans> GetExceptEquipNode()
    {
        List<LineMonitorBeans> query = new List<LineMonitorBeans>();
        try
        {
            var db = Db.Default;
            var settings = db.WmsSettings.Where(f => f.Code == ConstFields.CmdTimeOut).FirstOrDefault();
            int? cmdMaxTime = !string.IsNullOrWhiteSpace(settings.Value) ? Convert.ToInt32(settings.Value) : null;
            query = db.VExceptEquipNode.Select(f => new LineMonitorBeans
            {
                Id = f.Id,
                BoxCode = f.BoxCode,
                BoxTop = f.YAxis,
                BoxLeft = f.XAxis,
                BoxWidth = f.BoxWidth,
                BoxHeight = f.BoxHeight,
                BoxIndex = f.BoxIndex,
                UseFlag = f.EquipUseFlag,
                ShowName = f.ShowName,
                BoxName = f.BoxName,
                TaskNo = f.TaskNo,
                //Styles = GetStyles(f.TaskNo,f.ErrMsg,f.ErrEndTime,f.DitchUseFlag, f.ShowType,f.CmdCreateTime,f.ErrorTaskNo,
                //                    cmdMaxTime, f.ShowColor, f.BoxType, f.EquipEnable, null),
                //MouseOverResult = GetMouseOverResult(f.BoxType,f.TaskRemarkMemo,null,f.DitchUseFlag, f.ErrMsg,f.ErrEndTime, null,null, 
                //                    f.TargetLocName,f.CmdCreateTime,f.ErrorTaskNo,cmdMaxTime, f.TaskNo,f.CmdType, f.ShowName, f.BoxName, 
                //                    f.EquipEnable, null, f.ProductCode),

                Styles = GetStyleV2(new LineStyleParam
                {
                    TaskNo = f.TaskNo,
                    ErrMsg = f.ErrMsg,
                    ErrEndTime = f.ErrEndTime,
                    DitchUseFlag = f.DitchUseFlag,
                    ShowType = f.ShowType,
                    CmdCreateTime = f.CmdCreateTime,
                    ErrorTaskNo = f.ErrorTaskNo,
                    CmdMaxTime = cmdMaxTime,
                    ShowColor = f.ShowColor,
                    BoxType = f.BoxType,
                    EquipEnable = f.EquipEnable,
                    StartTaskType = 1,// f.StartTaskType,
                }),
                MouseOverResult = GetMouseOverResultV2(new LineMouseOverParam
                {
                    BoxType = f.BoxType,
                    TaskRemarkMemo = f.TaskRemarkMemo,
                    DitchUseFlag = f.DitchUseFlag,
                    ErrMsg = f.ErrMsg,
                    ErrEndTime = f.ErrEndTime,
                    TargetLocName = f.TargetLocName,
                    CmdCreateTime = f.CmdCreateTime,
                    ErrorTaskNo = f.ErrorTaskNo,
                    CmdMaxTime = cmdMaxTime,
                    TaskNo = f.TaskNo,
                    CmdType = f.CmdType,
                    ShowName = f.ShowName,
                    BoxName = f.BoxName,
                    EquipEnable = f.EquipEnable,
                    ProductCode = f.ProductCode
                }),
            }).ToList();
        }
        catch (Exception e)
        {

            Client.Log(new Log { Data = $"---------------线体上节点异常信息：{e}" });
        }

        return query;
    }

    /// <summary>
    /// 获取能从线体读取任务号的和不会有任务号的节点
    /// </summary>
    /// <returns></returns>
    public List<LineMonitorBeans> GetExceptEquipNodeV2()
    {
        List<LineMonitorBeans> query = new List<LineMonitorBeans>();
        try
        {
            var db = Db.Default;
            var settings = db.WmsSettings.Where(f => f.Code == ConstFields.CmdTimeOut).FirstOrDefault();
            int? cmdMaxTime = !string.IsNullOrWhiteSpace(settings.Value) ? Convert.ToInt32(settings.Value) : null;
            query = db.VExceptEquipNodeV2.Select(f => new LineMonitorBeans
            {
                Id = f.Id,
                BoxCode = f.BoxCode,
                BoxTop = f.YAxis,
                BoxLeft = f.XAxis,
                BoxWidth = f.BoxWidth,
                BoxHeight = f.BoxHeight,
                BoxIndex = f.BoxIndex,
                UseFlag = f.EquipUseFlag,
                ShowName = f.ShowName,
                BoxName = f.BoxName,
                TaskNo = f.TaskNo,
                BoxType = f.BoxType,
                EquipId = f.EquipId,

                //Styles = GetStyles(f.TaskNo,f.ErrMsg,f.ErrEndTime,f.DitchUseFlag, f.ShowType,f.CmdCreateTime,f.ErrorTaskNo,
                //                    cmdMaxTime, f.ShowColor, f.BoxType, f.EquipEnable, null),
                //MouseOverResult = GetMouseOverResult(f.BoxType,f.TaskRemarkMemo,null,f.DitchUseFlag, f.ErrMsg,f.ErrEndTime, null,null, 
                //                    f.TargetLocName,f.CmdCreateTime,f.ErrorTaskNo,cmdMaxTime, f.TaskNo,f.CmdType, f.ShowName, f.BoxName, 
                //                    f.EquipEnable, null, f.ProductCode),

                Styles = GetStyleV2(new LineStyleParam
                {
                    TaskNo = f.TaskNo,
                    ErrMsg = f.ErrMsg,
                    ErrEndTime = f.ErrEndTime,
                    DitchUseFlag = f.DitchUseFlag,
                    ShowType = f.ShowType,
                    CmdCreateTime = f.CmdCreateTime,
                    ErrorTaskNo = f.ErrorTaskNo,
                    CmdMaxTime = cmdMaxTime,
                    ShowColor = f.ShowColor,
                    BoxType = f.BoxType,
                    EquipEnable = f.EquipEnable,
                    StartTaskType = f.StartTaskType,
                    TargetLocName = f.TargetLocName,
                    LineSign = f.LineSign,
                }),
                MouseOverResult = GetMouseOverResultV2(new LineMouseOverParam
                {
                    BoxType = f.BoxType,
                    TaskRemarkMemo = f.TaskRemarkMemo,
                    DitchUseFlag = f.DitchUseFlag,
                    ErrMsg = f.ErrMsg,
                    ErrEndTime = f.ErrEndTime,
                    TargetLocName = f.TargetLocName,
                    CmdCreateTime = f.CmdCreateTime,
                    ErrorTaskNo = f.ErrorTaskNo,
                    CmdMaxTime = cmdMaxTime,
                    TaskNo = f.TaskNo,
                    CmdType = f.CmdType,
                    ShowName = f.ShowName,
                    BoxName = f.BoxName,
                    EquipEnable = f.EquipEnable,
                    ProductCode = f.ProductCode
                }),
            }).ToList();
        }
        catch (Exception e)
        {

            Client.Log(new Log { Data = $"---------------线体上节点异常信息：{e}" });
        }

        return query;
    }

    /// <summary>
    /// 获取货叉上的节点
    /// </summary>
    /// <returns></returns>
    public List<LineMonitorBeans> GetEquipCrnFolkNode()
    {
        List<LineMonitorBeans> query = new List<LineMonitorBeans>();
        try
        {
            var db = Db.Default;
            var settings = db.WmsSettings.Where(f => f.Code == ConstFields.CmdTimeOut).FirstOrDefault();
            int? cmdMaxTime = !string.IsNullOrWhiteSpace(settings.Value) ? Convert.ToInt32(settings.Value) : null;


            query = db.VEquipCrnFolkNode.Select(f => new LineMonitorBeans
            {
                Id = f.Id,
                BoxCode = f.BoxCode,
                BoxTop = f.YAxis,
                BoxLeft = f.XAxis,
                BoxWidth = f.BoxWidth,
                BoxHeight = f.BoxHeight,
                BoxIndex = f.BoxIndex,
                UseFlag = f.EquipUseFlag,
                ShowName = f.ShowName,
                BoxName = f.BoxName,
                TaskNo = f.TaskNo,
                Styles = GetEquipStyleV2(new LineStyleParam
                {
                    CmdType = f.CmdType,
                    CmdStatus = f.CmdStatus,
                    ErrMsg = f.ErrMsg,
                    ErrEndTime = f.ErrEndTime,
                    ParentErrMsg = f.ParentErrMsg,
                    ParentErrEndTime = f.ParentErrEndTime,
                    ShowType = f.ShowType,
                    CmdCreateTime = f.CmdCreateTime,
                    CmdMaxTime = cmdMaxTime,
                    ShowColor = f.ShowColor,
                    BoxType = f.BoxType,
                    EquipEnable = f.EquipEnable,
                    ParentEquipEnable = f.ParentEquipEnable
                }),
                MouseOverResult = GetMouseOverResultV2(new LineMouseOverParam
                {
                    BoxType = f.BoxType,
                    TaskRemarkMemo = f.TaskRemarkMemo,
                    ErrMsg = f.ErrMsg,
                    ParentEquipEnable = f.ParentEquipEnable,
                    ErrEndTime = f.ErrEndTime,
                    ParentErrEndTime = f.ParentErrEndTime,
                    TargetLocName = f.TargetLocName,
                    CmdCreateTime = f.CmdCreateTime,
                    CmdMaxTime = cmdMaxTime,
                    TaskNo = f.TaskNo,
                    CmdType = f.CmdType,
                    ShowName = f.ShowName,
                    BoxName = f.BoxName,
                    EquipEnable = f.EquipEnable,
                    ProductCode = f.ProductCode,
                    ParentErrMsg = f.ParentErrMsg
                }),
            }).ToList();
        }
        catch (Exception e)
        {

            Client.Log(new Log { Data = $"---------------货叉上节点异常信息：{e}" });
        }

        return query;
    }
    /// <summary>
    /// 获取货叉上的节点
    /// </summary>
    /// <returns></returns>
    public List<LineMonitorBeans> GetEquipCrnFolkNodeV2()
    {
        List<LineMonitorBeans> query = new List<LineMonitorBeans>();
        try
        {
            var db = Db.Default;
            var settings = db.WmsSettings.Where(f => f.Code == ConstFields.CmdTimeOut).FirstOrDefault();
            int? cmdMaxTime = !string.IsNullOrWhiteSpace(settings.Value) ? Convert.ToInt32(settings.Value) : null;


            query = db.VEquipCrnFolkNodeV2.Select(f => new LineMonitorBeans
            {
                Id = f.Id,
                BoxCode = f.BoxCode,
                BoxTop = f.YAxis,
                BoxLeft = f.XAxis,
                BoxWidth = f.BoxWidth,
                BoxHeight = f.BoxHeight,
                BoxIndex = f.BoxIndex,
                UseFlag = f.EquipUseFlag,
                ShowName = f.ShowName,
                BoxName = f.BoxName,
                TaskNo = f.TaskNo,
                BoxType = f.BoxType,
                Styles = GetEquipStyleV2(new LineStyleParam
                {
                    CmdType = f.CmdType,
                    CmdStatus = f.CmdStatus,
                    ErrMsg = f.ErrMsg,
                    ErrEndTime = f.ErrEndTime,
                    ParentErrMsg = f.ParentErrMsg,
                    ParentErrEndTime = f.ParentErrEndTime,
                    ShowType = f.ShowType,
                    CmdCreateTime = f.CmdCreateTime,
                    CmdMaxTime = cmdMaxTime,
                    ShowColor = f.ShowColor,
                    BoxType = f.BoxType,
                    EquipEnable = f.EquipEnable,
                    ParentEquipEnable = f.ParentEquipEnable,
                }),
                MouseOverResult = GetMouseOverResultV2(new LineMouseOverParam
                {
                    BoxType = f.BoxType,
                    TaskRemarkMemo = f.TaskRemarkMemo,
                    ErrMsg = f.ErrMsg,
                    ParentEquipEnable = f.ParentEquipEnable,
                    ErrEndTime = f.ErrEndTime,
                    ParentErrEndTime = f.ParentErrEndTime,
                    TargetLocName = f.TargetLocName,
                    CmdCreateTime = f.CmdCreateTime,
                    CmdMaxTime = cmdMaxTime,
                    TaskNo = f.TaskNo,
                    CmdType = f.CmdType,
                    ShowName = f.ShowName,
                    BoxName = f.BoxName,
                    EquipEnable = f.EquipEnable,
                    ProductCode = f.ProductCode,
                    ParentErrMsg = f.ParentErrMsg
                }),
            }).ToList();
        }
        catch (Exception e)
        {

            Client.Log(new Log { Data = $"---------------货叉上节点异常信息：{e}" });
        }

        return query;
    }

    /// <summary>
    /// 获取货叉上的节点
    /// </summary>
    /// <returns></returns>
    public List<LineMonitorBeans> GetEquipEMSNode()
    {
        List<LineMonitorBeans> query = new List<LineMonitorBeans>();
        try
        {
            var db = Db.Default;
            var settings = db.WmsSettings.Where(f => f.Code == ConstFields.CmdTimeOut).FirstOrDefault();
            int? cmdMaxTime = !string.IsNullOrWhiteSpace(settings.Value) ? Convert.ToInt32(settings.Value) : null;
            query = db.VEquipEMSNode.Select(f => new LineMonitorBeans
            {
                Id = f.Id,
                BoxCode = f.BoxCode,
                BoxTop = f.YAxis,
                BoxLeft = f.XAxis,
                BoxWidth = f.BoxWidth,
                BoxHeight = f.BoxHeight,
                BoxIndex = f.BoxIndex,
                UseFlag = f.EquipUseFlag,
                ShowName = f.ShowName,
                BoxName = f.BoxName,
                TaskNo = f.TaskNo,

                Styles = GetEquipStyleV2(new LineStyleParam
                {
                    CmdType = f.CmdType,
                    CmdStatus = f.CmdStatus,
                    ErrMsg = f.ErrMsg,
                    ErrEndTime = f.ErrEndTime,
                    ParentErrMsg = f.ParentErrMsg,
                    ParentErrEndTime = f.ParentErrEndTime,
                    ShowType = f.ShowType,
                    CmdCreateTime = f.CmdCreateTime,
                    CmdMaxTime = cmdMaxTime,
                    ShowColor = f.ShowColor,
                    BoxType = f.BoxType,
                    EquipEnable = f.EquipEnable,
                    ParentEquipEnable = f.ParentEquipEnable
                }),
                MouseOverResult = GetMouseOverResultV2(new LineMouseOverParam
                {
                    BoxType = f.BoxType,
                    TaskRemarkMemo = f.TaskRemarkMemo,
                    ErrMsg = f.ErrMsg,
                    ParentEquipEnable = f.ParentEquipEnable,
                    ErrEndTime = f.ErrEndTime,
                    ParentErrMsg = f.ParentErrMsg,
                    ParentErrEndTime = f.ParentErrEndTime,
                    TargetLocName = f.TargetLocName,
                    CmdCreateTime = f.CmdCreateTime,
                    CmdMaxTime = cmdMaxTime,
                    TaskNo = f.TaskNo,
                    CmdType = f.CmdType,
                    ShowName = f.ShowName,
                    BoxName = f.BoxName,
                    EquipEnable = f.EquipEnable,
                    ProductCode = f.ProductCode
                }),

            }).ToList();
        }
        catch (Exception e)
        {

            Client.Log(new Log { Data = $"---------------EMS上节点异常信息：{e}" });
        }

        return query;
    }

    /// <summary>
    /// 获取货叉上的节点
    /// </summary>
    /// <returns></returns>
    public List<LineMonitorBeans> GetEquipEMSNodeV2()
    {
        List<LineMonitorBeans> query = new List<LineMonitorBeans>();
        try
        {
            var db = Db.Default;
            var settings = db.WmsSettings.Where(f => f.Code == ConstFields.CmdTimeOut).FirstOrDefault();
            int? cmdMaxTime = !string.IsNullOrWhiteSpace(settings.Value) ? Convert.ToInt32(settings.Value) : null;
            query = db.VEquipEMSNodeV2.Select(f => new LineMonitorBeans
            {
                Id = f.Id,
                BoxCode = f.BoxCode,
                BoxTop = f.YAxis,
                BoxLeft = f.XAxis,
                BoxWidth = f.BoxWidth,
                BoxHeight = f.BoxHeight,
                BoxIndex = f.BoxIndex,
                UseFlag = f.EquipUseFlag,
                ShowName = f.ShowName,
                BoxName = f.BoxName,
                TaskNo = f.TaskNo,
                BoxType = f.BoxType,
                Styles = GetEquipStyleV2(new LineStyleParam
                {
                    CmdType = f.CmdType,
                    CmdStatus = f.CmdStatus,
                    ErrMsg = f.ErrMsg,
                    ErrEndTime = f.ErrEndTime,
                    ParentErrMsg = f.ParentErrMsg,
                    ParentErrEndTime = f.ParentErrEndTime,
                    ShowType = f.ShowType,
                    CmdCreateTime = f.CmdCreateTime,
                    CmdMaxTime = cmdMaxTime,
                    ShowColor = f.ShowColor,
                    BoxType = f.BoxType,
                    EquipEnable = f.EquipEnable,
                    ParentEquipEnable = f.ParentEquipEnable
                }),
                MouseOverResult = GetMouseOverResultV2(new LineMouseOverParam
                {
                    BoxType = f.BoxType,
                    TaskRemarkMemo = f.TaskRemarkMemo,
                    ErrMsg = f.ErrMsg,
                    ParentEquipEnable = f.ParentEquipEnable,
                    ErrEndTime = f.ErrEndTime,
                    ParentErrMsg = f.ParentErrMsg,
                    ParentErrEndTime = f.ParentErrEndTime,
                    TargetLocName = f.TargetLocName,
                    CmdCreateTime = f.CmdCreateTime,
                    CmdMaxTime = cmdMaxTime,
                    TaskNo = f.TaskNo,
                    CmdType = f.CmdType,
                    ShowName = f.ShowName,
                    BoxName = f.BoxName,
                    EquipEnable = f.EquipEnable,
                    ProductCode = f.ProductCode
                }),

            }).ToList();
        }
        catch (Exception e)
        {

            Client.Log(new Log { Data = $"---------------EMS上节点异常信息：{e}" });
        }

        return query;
    }
    /// <summary>
    /// 获取堆垛机上的节点
    /// </summary>
    /// <returns></returns>
    public List<LineMonitorBeans> GetEquipCrnNode()
    {
        List<LineMonitorBeans> query = new List<LineMonitorBeans>();
        try
        {
            var db = Db.Default;
            var settings = db.WmsSettings.Where(f => f.Code == ConstFields.CmdTimeOut).FirstOrDefault();
            int? cmdMaxTime = !string.IsNullOrWhiteSpace(settings.Value) ? Convert.ToInt32(settings.Value) : null;


            query = db.VEquipCrnNode.Select(f => new LineMonitorBeans
            {
                Id = f.Id,
                BoxCode = f.BoxCode,
                BoxTop = f.YAxis,
                BoxLeft = f.XAxis,
                BoxWidth = f.BoxWidth,
                BoxHeight = f.BoxHeight,
                BoxIndex = f.BoxIndex,
                UseFlag = f.EquipUseFlag,
                ShowName = f.ShowName,
                BoxName = f.BoxName,
                TaskNo = f.TaskNo,
                //Styles = GetStyles(f.TaskNo,f.ErrMsg, f.ErrEndTime, f.DitchUseFlag, f.ShowType, f.CmdCreateTime, f.ErrorTaskNo, 
                //                    cmdMaxTime, f.ShowColor, f.BoxType, f.EquipEnable, null),
                //MouseOverResult = GetMouseOverResult(f.BoxType,null,f.EmptyCount, f.DitchUseFlag, f.ErrMsg,f.ErrEndTime, null,null, f.TargetLocName, f.CmdCreateTime, 
                //                                    f.ErrorTaskNo, cmdMaxTime, f.TaskNo, f.CmdType, f.ShowName, f.BoxName, f.EquipEnable, null, f.ProductCode),

                Styles = GetStyleV2(new LineStyleParam
                {
                    TaskNo = f.TaskNo,
                    ErrMsg = f.ErrMsg,
                    ErrEndTime = f.ErrEndTime,
                    DitchUseFlag = f.DitchUseFlag,
                    ShowType = f.ShowType,
                    CmdCreateTime = f.CmdCreateTime,
                    ErrorTaskNo = f.ErrorTaskNo,
                    CmdMaxTime = cmdMaxTime,
                    ShowColor = f.ShowColor,
                    BoxType = f.BoxType,
                    EquipEnable = f.EquipEnable,
                    StartTaskType = 1,
                }),
                MouseOverResult = GetMouseOverResultV2(new LineMouseOverParam
                {
                    BoxType = f.BoxType,
                    ErrMsg = f.ErrMsg,
                    EmptyCount = f.EmptyCount,
                    DitchUseFlag = f.DitchUseFlag,
                    ErrEndTime = f.ErrEndTime,
                    TargetLocName = f.TargetLocName,
                    CmdCreateTime = f.CmdCreateTime,
                    CmdMaxTime = cmdMaxTime,
                    ErrorTaskNo = f.ErrorTaskNo,
                    TaskNo = f.TaskNo,
                    CmdType = f.CmdType,
                    ShowName = f.ShowName,
                    BoxName = f.BoxName,
                    EquipEnable = f.EquipEnable,
                    ProductCode = f.ProductCode
                }),

            }).ToList();

        }
        catch (Exception e)
        {

            Client.Log(new Log { Data = $"---------------堆垛机上节点异常信息：{e}" });
        }

        return query;
    }

    /// <summary>
    /// 获取堆垛机上的节点(新)
    /// </summary>
    /// <returns></returns>
    public List<LineMonitorBeans> GetEquipCrnNodeV2()
    {
        List<LineMonitorBeans> query = new List<LineMonitorBeans>();
        try
        {
            var db = Db.Default;
            var settings = db.WmsSettings.Where(f => f.Code == ConstFields.CmdTimeOut).FirstOrDefault();
            int? cmdMaxTime = !string.IsNullOrWhiteSpace(settings.Value) ? Convert.ToInt32(settings.Value) : null;


            query = db.VEquipCrnNodeV2.Select(f => new LineMonitorBeans
            {
                Id = f.Id,
                BoxCode = f.BoxCode,
                BoxTop = f.YAxis,
                BoxLeft = f.XAxis,
                BoxWidth = f.BoxWidth,
                BoxHeight = f.BoxHeight,
                BoxIndex = f.BoxIndex,
                UseFlag = f.EquipUseFlag,
                ShowName = f.ShowName,
                BoxName = f.BoxName,
                TaskNo = f.TaskNo,
                TaskNo2 = f.TaskNo2,
                BoxType = f.BoxType,
                //Styles = GetStyles(f.TaskNo,f.ErrMsg, f.ErrEndTime, f.DitchUseFlag, f.ShowType, f.CmdCreateTime, f.ErrorTaskNo, 
                //                    cmdMaxTime, f.ShowColor, f.BoxType, f.EquipEnable, null),
                //MouseOverResult = GetMouseOverResult(f.BoxType,null,f.EmptyCount, f.DitchUseFlag, f.ErrMsg,f.ErrEndTime, null,null, f.TargetLocName, f.CmdCreateTime, 
                //                                    f.ErrorTaskNo, cmdMaxTime, f.TaskNo, f.CmdType, f.ShowName, f.BoxName, f.EquipEnable, null, f.ProductCode),

                Styles = GetStyleV2(new LineStyleParam
                {
                    TaskNo = f.TaskNo,
                    ErrMsg = f.ErrMsg,
                    ErrEndTime = f.ErrEndTime,
                    DitchUseFlag = f.DitchUseFlag,
                    ShowType = f.ShowType,
                    CmdCreateTime = f.CmdCreateTime,
                    ErrorTaskNo = f.ErrorTaskNo,
                    CmdMaxTime = cmdMaxTime,
                    ShowColor = f.ShowColor,
                    BoxType = f.BoxType,
                    EquipEnable = f.EquipEnable,
                    StartTaskType = f.StartTaskType,
                    TargetLocName = f.TargetLocName
                }),
                MouseOverResult = GetMouseOverResultV2(new LineMouseOverParam
                {
                    BoxType = f.BoxType,
                    ErrMsg = f.ErrMsg,
                    EmptyCount = f.EmptyCount,
                    DitchUseFlag = f.DitchUseFlag,
                    ErrEndTime = f.ErrEndTime,
                    TargetLocName = f.TargetLocName,
                    CmdCreateTime = f.CmdCreateTime,
                    CmdMaxTime = cmdMaxTime,
                    ErrorTaskNo = f.ErrorTaskNo,
                    TaskNo = f.TaskNo,
                    TaskNo2 = f.TaskNo2,
                    CmdType = f.CmdType,
                    ShowName = f.ShowName,
                    BoxName = f.BoxName,
                    EquipEnable = f.EquipEnable,
                    ProductCode = f.ProductCode
                }),

            }).ToList();

        }
        catch (Exception e)
        {

            Client.Log(new Log { Data = $"---------------堆垛机上节点异常信息：{e}" });
        }

        return query;
    }


    /// <summary>
    /// 获取成型机上的节点
    /// </summary>
    /// <returns></returns>
    public List<LineMonitorBeans> GetEquipBuildingNode()
    {
        List<LineMonitorBeans> query = new List<LineMonitorBeans>();
        try
        {
            var db = Db.Default;
            ////WriteLog($"提升机监控{db.VEquipBuildingNode.ToList().ToJson()}", true);
            query = db.VEquipBuildingNode.Select(f => new LineMonitorBeans
            {
                Id = f.Id,
                BoxCode = f.BoxCode,
                BoxTop = f.YAxis,
                BoxLeft = f.XAxis,
                BoxWidth = f.BoxWidth,
                BoxHeight = f.BoxHeight,
                BoxIndex = f.BoxIndex,
                UseFlag = f.EquipUseFlag,
                ShowName = f.ShowName,
                BoxName = f.BoxName,

                Styles = GetStyleV2(new LineStyleParam
                {
                    ShowType = f.ShowType,
                    ShowColor = f.ShowColor,
                    BoxType = f.BoxType,
                    EquipEnable = f.EquipEnable,
                    EquipStatus = f.EquipStatus,
                    StartTaskType = 1,
                }),
                MouseOverResult = GetMouseOverResultV2(new LineMouseOverParam
                {
                    BoxType = f.BoxType,
                    ShowName = f.ShowName,
                    BoxName = f.BoxName,
                    EquipEnable = f.EquipEnable,
                    EquipStatus = f.EquipStatus,
                    ReamrkMemo = f.ReamrkMemo,
                    BuildingCode = f.BuildingCode,
                    EquipMaterial = f.EquipMaterial,
                }),
            }).ToList();
        }
        catch (Exception e)
        {

            Client.Log(new Log { Data = $"---------------成型机上节点异常信息：{e}" });
        }

        return query;
    }

    /// <summary>
    /// 获取成型机上的节点
    /// </summary>
    /// <returns></returns>
    public List<LineMonitorBeans> GetEquipBuildingNodeV2()
    {
        List<LineMonitorBeans> query = new List<LineMonitorBeans>();
        try
        {
            var db = Db.Default;
            ////WriteLog($"提升机监控{db.VEquipBuildingNode.ToList().ToJson()}", true);
            query = db.VEquipBuildingNodeV2.Select(f => new LineMonitorBeans
            {
                Id = f.Id,
                BoxCode = f.BoxCode,
                BoxTop = f.YAxis,
                BoxLeft = f.XAxis,
                BoxWidth = f.BoxWidth,
                BoxHeight = f.BoxHeight,
                BoxIndex = f.BoxIndex,
                UseFlag = f.EquipUseFlag,
                ShowName = f.ShowName,
                BoxName = f.BoxName,

                Styles = GetStyleV2(new LineStyleParam
                {
                    ShowType = f.ShowType,
                    ShowColor = f.ShowColor,
                    BoxType = f.BoxType,
                    EquipEnable = f.EquipEnable,
                    EquipStatus = f.EquipStatus,
                    StartTaskType = 1,
                }),
                MouseOverResult = GetMouseOverResultV2(new LineMouseOverParam
                {
                    BoxType = f.BoxType,
                    ShowName = f.ShowName,
                    BoxName = f.BoxName,
                    EquipEnable = f.EquipEnable,
                    EquipStatus = f.EquipStatus,
                    ReamrkMemo = f.ReamrkMemo,
                    BuildingCode = f.BuildingCode,
                    EquipMaterial = f.EquipMaterial,
                }),
            }).ToList();
        }
        catch (Exception e)
        {

            Client.Log(new Log { Data = $"---------------成型机上节点异常信息：{e}" });
        }

        return query;
    }

    public List<LineMonitorBeans> GetCuringNodes()
    {
        var db = Db.Default;

        var allCuringNoOrders = GetAllCuringNoOrder();
        var allCuringOrders = GetAllCuringHaveOrder();


        var beans = db.ScadaBoxs.Join(db.RcsEquipCurings, f => f.EquipId, s => s.Id, (f, s) => new { Box = f, Curing = s })
            .Where(item => (item.Box.BoxType == (int)EnumScadaBoxType.ScadaCuring
            || item.Box.BoxType == (int)EnumScadaBoxType.ScadaArm
            || item.Box.BoxType == (int)EnumScadaBoxType.ScadaReceivePlatForm) && item.Box.UseFlag == 1).Select(f => new LineMonitorBeans()
            {
                Id = f.Box.Id,
                LocId = f.Box.LocId,
                BoxCode = f.Box.BoxCode,
                BoxTop = f.Box.BoxTop,
                BoxLeft = f.Box.BoxLeft,
                BoxWidth = f.Box.BoxWidth,
                BoxHeight = f.Box.BoxHeight,
                BoxIndex = f.Box.BoxIndex,
                ShowCode = f.Box.ShowCode,
                ShowName = f.Box.ShowName,
                BoxName = f.Box.BoxName,

                ShowType = f.Box.ShowType,
                BoxType = f.Box.BoxType,
                TcmSpec = f.Box.TcmSpec,
                TcmSpecDesc = f.Box.TcmSpecDesc,
                //MouseOverResult = f.Curing.Remark,
                EquipId = f.Box.EquipId,
                RvcFlag = f.Box.RcvFlag,
            }).ToList();

        var tcmSpecs = beans.Select(f => f.TcmSpec).Distinct().ToList();

        //var specList = GetCuringStock(tcmSpecs);

        //var settings = db.WmsSettings.Where(f => f.Code == ConstFields.CmdTimeOut).FirstOrDefault();
        int? cmdMaxTime = 10;// !string.IsNullOrWhiteSpace(settings.Value) ? Convert.ToInt32(settings.Value) : 10;

        foreach (var bean in beans)
        {
            var lineParam = new LineStyleParam()
            {
                ShowColor = bean.Styles,
                ShowType = bean.ShowType,
                ShowCode = bean.ShowCode,
                BoxName = bean.BoxName,
                CmdMaxTime = cmdMaxTime,
                tcmSpec = bean.TcmSpec,
                BoxType = bean.BoxType,
                EquipId = bean.EquipId,
                BoxCode = bean.BoxCode,
                SpecCount = 0,// specList.Where(f => f.Spec == bean.TcmSpec).Select(f => f.Count).FirstOrDefault(),
                RcvFlag = bean.RvcFlag,

            };

            var mouseParam = new LineMouseOverParam()
            {
                ShowCode = bean.UseFlag,
                BoxName = bean.BoxName,
                CmdMaxTime = cmdMaxTime,
                ShowName = bean.ShowName,
                TcmSpec = bean.TcmSpec,
                TcmSpecDesc = bean.TcmSpecDesc,
                BoxCode = bean.BoxCode,//bean.BoxCode.Substring(0, 9),
                SpecCount = 0,// specList.Where(f => f.Spec == bean.TcmSpec).Select(f => f.Count).FirstOrDefault(),
                Remark = bean.MouseOverResult,

            };

            //var taskBean = taskBeans.Where(f => f.LocId == bean.LocId).ToList();

            //if (taskBean.Any())
            //{
            //    //WriteLog($"设备{bean.BoxCode},任务{taskBean.FirstOrDefault().TaskNo}", true);
            //    lineParam.CmdCreateTime = taskBean.OrderBy(f => f.CmdCreateTime).FirstOrDefault()?.CmdCreateTime;

            //    mouseParam.CmdCreateTime = taskBean.OrderBy(f => f.CmdCreateTime).FirstOrDefault()?.CmdCreateTime;

            //    lineParam.TaskNo = taskBean.OrderBy(f => f.CmdCreateTime).FirstOrDefault()?.TaskNo;

            //    mouseParam.TaskNo = taskBean.OrderBy(f => f.CmdCreateTime).FirstOrDefault()?.TaskNo;

            //    mouseParam.ProductCode = taskBean.OrderBy(f => f.CmdCreateTime).FirstOrDefault()?.ProductCode;
            //}

            var curingNoOrders = allCuringNoOrders.Where(t => t.CuringCode == bean.BoxCode).ToList();
            var curingOrders = allCuringOrders.Where(t => t.CuringCode == bean.BoxCode).ToList();

            bean.Styles = GetCuringStyle(lineParam, curingNoOrders, curingOrders);
            if (bean.BoxType == (int)EnumScadaBoxType.ScadaCuring)
            {
                bean.BoxName = bean.ShowName;
                bean.MouseOverResult = GetCuringMouseOverResult(mouseParam, curingNoOrders, curingOrders);
            }

        }


        return beans;
    }



    public CuringListBeans GetCuringNodesByEquipId(long equipId)
    {
        CuringListBeans result = new();
        var db = Db.Default;

        var allCuringNoOrders = GetAllCuringNoOrder();
        var allCuringOrders = GetAllCuringHaveOrder();


        //var seBox = db.SeBoxs.Join(db.RcsEquipCurings, f => f.EquipId, s => s.Id, (f, s) => new { Box = f, Curing = s })
        //    .Where(t => t.Box.EquipId == equipId).Select(t=>t.Box).FirstOrDefault();
        //if (seBox is null) 
        //{
        //    return result;
        //}


        var seBox = db.ScadaBoxs.Where(t => t.EquipId == equipId).FirstOrDefault();
        if (seBox is null)
        {
            return result;
        }


        var curingNoOrders = allCuringNoOrders.Where(t => t.CuringCode == seBox.BoxCode).ToList();
        var curingOrders = allCuringOrders.Where(t => t.CuringCode == seBox.BoxCode).ToList();

        //if (bean.BoxType == (int)EnumScadaBoxType.ScadaCuring)
        //{
        //    bean.BoxName = bean.ShowName;
        //    bean.MouseOverResult = GetCuringMouseOverResult(mouseParam, curingNoOrders, curingOrders);
        //}

        result = GetCuringDetails(seBox, curingNoOrders, curingOrders);

        //result.CuringDetails


        return result;
    }



    public List<StockBeans> GetStockByMaterialCode(string materialCode)
    {
        var db = Db.Default;
        List<StockBeans> result = new();
        result = db.WcsLocSkus.Join(db.RcsLocations, f => f.LocId, s => s.Id, (f, s) => new
        {
            f.SkuId,
            s.LocType,
            s.LocEnable,
            s.InEnable,
            s.OutEnable,
        }).Where(t => t.LocEnable == 1 && t.InEnable == 1 && t.OutEnable == 1)
        .Join(db.ProdSkuProducts, f => f.SkuId, s => s.SkuId, (f, s) => new
        {
            f.LocType,
            s.ProductId,
        }).Join(db.ProdProducts, f => f.ProductId, s => s.Id, (f, s) => new
        {
            f.LocType,
            f.ProductId,
            s.ProductCode,
            s.MaterialId,
            s.TireLock,
            s.TbmExpirationTime,
        }).Join(db.ProdMaterials, f => f.MaterialId, s => s.Id, (f, s) => new
        {
            f.LocType,
            f.ProductCode,
            f.MaterialId,
            f.TireLock,
            f.TbmExpirationTime,
            s.MaterialCode,
        }).Where(t => t.MaterialCode == materialCode && t.LocType == (int)EnumLocType.Location)
        .Select(t => new StockBeans
        {
            MaterialCode = t.MaterialCode,
            MaterialId = t.MaterialId,
            TireLock = t.TireLock,
            ProductCode = t.ProductCode,
            TbmExpirationTime = t.TbmExpirationTime,
        }).ToList();

        return result;
    }

    private CuringListBeans GetCuringDetails(POScadaBox seBox, List<CuringMessageBeans> curingNoOrders, List<CuringMessageBeans> curingOrders)
    {


        CuringListBeans result = new();
        List<CuringDetailsBeans> curingDetailsList = new();

        CuringDetailsBeans curingDetailsL = new();
        CuringDetailsBeans curingDetailsR = new();
        curingDetailsL.CuringMode = "左L";
        curingDetailsR.CuringMode = "右R";

        //WriteLog($"curingNoOrder详情{curingNoOrders.ToJson()}", true);
        //WriteLog($"curingOrders详情{curingOrders.ToJson()}", true);
        //WriteLog($"seBox{seBox.ToJson()}", true);

        //if (!String.IsNullOrWhiteSpace(result))

        //{
        //    result = result + $"<br>设备编号：{param?.BoxCode}" + $"<br>设备名：{param.ShowName}";
        //}
        //else
        //{
        // result = result + $"设备名：{param.ShowName}<br>";
        //}

        //var curingCode = seBox.ShowCode;
        var materialCode = seBox.TcmSpec;
        var materialName = seBox.TcmSpecDesc;
        var curingTime = seBox.RegDt;
        result.CuringCode = seBox.ShowName;


        var stocks = GetStockByMaterialCode(materialCode);

        var stockCount = stocks.Where(t => t.TireLock == 0 && t.TbmExpirationTime >= DateTime.Now).Count();
        var timeOutCount = stocks.Where(t => t.TireLock == 0 && t.TbmExpirationTime < DateTime.Now).Count();
        var lockCount = stocks.Where(t => t.TireLock == 1).Count();
        var experimentCount = 0;


        var orderCount = 0;
        var taskCount = 0;
        var planCount = 0;



        //判断是否有订单(没有订单)
        if (curingNoOrders.Count > 0)
        {
            if (curingNoOrders.Count >= 2)
            {
                //if (!String.IsNullOrWhiteSpace(result))
                //{
                //    result = result + "<br>";
                //}
                result.Remark = "订单状态：未生成订单";
                orderCount = 0;

                if (seBox.RcvFlag == "Y")
                {
                    planCount = 2;
                    curingDetailsL.MaterialCode = materialCode;
                    curingDetailsL.MaterialName = materialName;
                    curingDetailsR.MaterialCode = materialCode;
                    curingDetailsR.MaterialName = materialName;
                }
                else
                {
                    planCount = 0;
                    stockCount = 0;
                    timeOutCount = 0;
                    lockCount = 0;
                    curingTime = null;
                }
            }                                  
            else
            {
                var curingNoOrderL = curingNoOrders.Where(t => t.LeftRightFlag == "L").FirstOrDefault();
                if (curingNoOrderL is not null)
                {

                    result.Remark = $"订单状态：L：未生成订单，R：已生成订单";
                    orderCount = 1;
                }
                else
                {

                    result.Remark = $"订单状态：L：已生成订单，R：未生成订单";
                    orderCount = 1;
                }

            }
            //var curingNoOrders.Where(t => t.LeftRightFlag == "L").FirstOrDefault();
        }
        else
        {
            //判断任务
            var curingtaskOrders = curingOrders.Where(t => t.TaskNo > 0).ToList();
            var curingtaskOrderL = curingtaskOrders.Where(t => t.LeftRightFlag == "L").FirstOrDefault();
            var curingtaskOrderR = curingtaskOrders.Where(t => t.LeftRightFlag == "R").FirstOrDefault();

            if (curingtaskOrders is not null && curingtaskOrders.Count > 0)
            {
                planCount = 2;
                orderCount = 2;
                result.Remark = $"规格{materialCode}已经创建订单";

                if (curingtaskOrderL is not null)
                {
                    curingDetailsL.TaskNo = curingtaskOrderL.TaskNo;
                    curingDetailsL.ProductCode = curingtaskOrderL.SkuCode;

                    taskCount += 1;
                    //result.Remark += $"L - 任务号：{curingtaskOrderL.TaskNo}  ,  L - 条码：{curingtaskOrderL.SkuCode} ";
                }
                else
                {
                    curingDetailsL.TaskNo = 0;
                    curingDetailsL.ProductCode = "";
                    //result.Remark = $"L - 未创建";
                }



                if (curingtaskOrderR is not null)
                {
                    curingDetailsR.TaskNo = curingtaskOrderR.TaskNo;
                    curingDetailsR.ProductCode = curingtaskOrderR.SkuCode;
                    taskCount += 1;
                    //result.Remark += "R - 任务号：{curingtaskOrderL.TaskNo}  ,  L - 条码：{curingtaskOrderL.SkuCode}";
                }
                else
                {
                    curingDetailsR.TaskNo = 0;
                    curingDetailsR.ProductCode = "";
                    //result.Remark +=  "R - 未创建任务 ";
                }

            }
            else
            {
                planCount = 2;
                curingDetailsL.TaskNo = 0;
                curingDetailsL.ProductCode = "";
                curingDetailsR.TaskNo = 0;
                curingDetailsR.ProductCode = "";

                //result = result + "L-任务号：未创建 ，L-条码：未创建<br>";
                //result = result + "R-任务号：未创建 ，R-条码：未创建<br>";

                var curingOrderL = curingOrders.Where(t => t.LeftRightFlag == "L").FirstOrDefault();
                var curingOrderR = curingOrders.Where(t => t.LeftRightFlag == "R").FirstOrDefault();
                if (curingOrderL is not null)
                {
                    result.Remark += $"L-无订单原因：{curingOrderL.SummaryReamrk} ";
                    //result = result + "L-无订单原因：" + curingOrderL.SummaryReamrk + "<br>";
                }
                if (curingOrderR is not null)
                {
                    result.Remark += $"R-无订单原因：{curingOrderR.SummaryReamrk} ";
                    //result = result + "R-无订单原因：" + curingOrderR.SummaryReamrk + "<br>";
                }

            }




            //var materialName = "";
            if (!string.IsNullOrWhiteSpace(materialCode))
            {
                //var material = _ProdMaterial.GetMaterialByCode(materialCode);
                //materialName = material?.MaterialName ?? "";

                curingDetailsL.MaterialCode = materialCode;
                curingDetailsR.MaterialCode = materialCode;

                curingDetailsL.MaterialName = materialName;
                curingDetailsR.MaterialName = materialName;


            }
            else
            {
                materialName = $"硫化物料：MES未传递硫化物料";

                curingDetailsL.MaterialName = materialName;
                curingDetailsR.MaterialName = materialName;
            }

        }
        curingDetailsList.Add(curingDetailsL);
        curingDetailsList.Add(curingDetailsR);
        result.CuringDetails = curingDetailsList;
        result.PlanCount = planCount;
        result.OrderCount = orderCount; 
        result.TaskCount = taskCount;
        result.ExperimentCount = 0;
        result.StockCount = stockCount;
        result.TimeOutCount = timeOutCount;
        result.LockCount = lockCount;
        result.ExperimentCount = experimentCount;
        result.CuringTime = curingTime;


        //WriteLog($"硫化机详情{result.ToJson()}", true);
        return result;
    }

    /// <summary>
    /// 获取成型机上的节点
    /// </summary>
    /// <returns></returns>
    public List<LineMonitorBeans> GetEquipElementNode()
    {
        List<LineMonitorBeans> query = new List<LineMonitorBeans>();
        try
        {
            var db = Db.Default;

            query = db.SeBoxs
               .Where(item => (item.BoxType == (int)EnumScadaBoxType.ScadaCircular
               || item.BoxType == (int)EnumScadaBoxType.ScadaArrow
               || item.BoxType == (int)EnumScadaBoxType.ScadaLine)
               && item.UseFlag == 1).Select(f => new LineMonitorBeans()
               {
                   Id = f.Id,
                   LocId = f.LocId,
                   BoxCode = f.BoxCode,
                   BoxTop = f.BoxTop,
                   BoxLeft = f.BoxLeft,
                   BoxWidth = f.BoxWidth,
                   BoxHeight = f.BoxHeight,
                   BoxIndex = f.BoxIndex,
                   ShowCode = f.ShowCode,
                   ShowName = f.ShowName,
                   BoxName = f.BoxName,
                   //Styles = f.ShowColor,
                   ShowType = f.ShowType,
                   BoxType = f.BoxType,
                   Styles = GetStyleV2(new LineStyleParam
                   {
                       ShowType = f.ShowType,
                       ShowColor = f.ShowColor,
                       BoxType = f.BoxType,
                   }),
                   MouseOverResult = GetMouseOverResultV2(new LineMouseOverParam
                   {
                       BoxType = f.BoxType,
                       ShowName = f.ShowName,
                       BoxName = f.BoxName,
                   }),
                   //TcmSpec = f.TcmSpec,
                   //TcmSpecDesc = f.TcmSpecDesc,
                   //MouseOverResult = f.Remark,
               }).ToList();

        }
        catch (Exception e)
        {

            Client.Log(new Log { Data = $"---------------成型机上节点异常信息：{e}" });
        }

        return query;
    }


    //public List<SpecStock> GetCuringStock(List<string> tcmSpecs)
    //{
    //    var db = Db.Default;

    //    var specList = db.WcsLocSkus.Join(db.RcsLocations, f => f.LocId, s => s.Id, (f, s) => new { Loc = s, Sku = f })
    //                       .Join(db.ProdProducts, f => f.Sku.SkuId, s => s.Id, (f, s) => new { Loc = f.Loc, Sku = f.Sku, Product = s })
    //                       .Where(f => tcmSpecs.Contains(f.Product.MaterialCode) && f.Loc.LocEnable == 1 && f.Loc.TaskOccupy == 0 && f.Loc.LocHasSku == 1 && f.Product.TireLock == 0 && f.Loc.LocType == (int)EnumLocType.Location).ToList();

    //    List<SpecStock> specStocks = new List<SpecStock>();

    //    foreach (var tcmspec in tcmSpecs)
    //    {
    //        specStocks.Add(new() { Spec = tcmspec, Count = specList.Count(f => f.Product.MaterialCode == tcmspec) });
    //    }

    //    return specStocks;
    //}


    /// <summary>
    /// 获取鼠标悬停的结果
    /// </summary>
    /// <param name="boxType"></param>
    /// <param name="taskNo"></param>
    /// <param name="showName"></param>
    /// <param name="boxName"></param>
    /// <returns></returns>
    public static string GetMouseOverResult(int? boxType, string taskRemarkMemo, int? emptyCount, int? ditchUseFlag, string errMsg, DateTime? errEndTime,
                                            string parentErrMsg, DateTime? parentErrEndTime, string targetLocName, DateTime? cmdCreateTime, int? errorTaskNo,
                                            int? cmdMaxTime, int? taskNo, int? cmdType, string showName, string boxName, int? equiipEnable, int? parentEquipEnable,
                                            string ProductCode)
    {
        string result = "";

        if (boxType is null)
        {
            return result;
        }
        if (taskNo is not null && taskNo > 0)
        {

            result = result + "任务号：" + taskNo;

            if (!string.IsNullOrWhiteSpace(ProductCode))
            {
                result = result + "<br/>条码：" + ProductCode;
            }

            switch (cmdType)
            {
                case (int)EnumTaskType.Abnormal:
                    result = result + "<br/>任务类型：异常任务";
                    break;
                case (int)EnumTaskType.EMS:
                    result = result + "<br/>任务类型：EMS任务";
                    break;
                case (int)EnumTaskType.Exwarehouse:
                    result = result + "<br/>任务类型：出库任务";
                    break;
                case (int)EnumTaskType.Rotate:
                    result = result + "<br/>任务类型：旋转任务";
                    break;
                case (int)EnumTaskType.Transportation:
                    result = result + "<br/>任务类型：输送任务";
                    break;
                case (int)EnumTaskType.Warehousing:
                    result = result + "<br/>任务类型：入库任务";
                    break;
            }

            if (!string.IsNullOrWhiteSpace(targetLocName))
            {
                result = result + "<br/>去向：" + targetLocName;
            }

            if (!string.IsNullOrWhiteSpace(taskRemarkMemo))
            {
                result = result + "<br/>说明：" + taskRemarkMemo;
            }
        }


        if (boxType == (int)EnumScadaBoxType.Lines)
        {
            if (taskNo is not null && taskNo > 0)
                result = result + "<br/>线体编号：" + showName;
            else
                result = result + "线体编号：" + showName;

            if (!string.IsNullOrWhiteSpace(errMsg) && errEndTime is null)
            {
                result = result + "<br/>线体状态：报警中";
                if (!string.IsNullOrWhiteSpace(errMsg)) result = result + "<br/>报警信息：" + errMsg;
            }
        }

        if (boxType != (int)EnumScadaBoxType.Lines && boxType != (int)EnumScadaBoxType.Description && boxType != (int)EnumScadaBoxType.CuringRow)
        {
            if (boxType == (int)EnumScadaBoxType.CrnFolk || boxType == (int)EnumScadaBoxType.EMS)
            {
                if (taskNo is not null && taskNo > 0)
                    result = result + "<br/>设备：" + showName;
                else
                    result = result + "设备：" + showName;


            }
            else
            {
                if (taskNo is not null && taskNo > 0)
                    result = result + "<br/>设备：" + boxName;
                else
                    result = result + "设备：" + boxName;
            }


            if (equiipEnable == 1)
            {
                if (parentEquipEnable is not null && parentEquipEnable == 0)
                    result = result + "<br/>设备状态：不可用";
                else
                    if (!string.IsNullOrWhiteSpace(errMsg) && errEndTime is null)
                {
                    result = result + "<br/>设备状态：报警中";
                    if (!string.IsNullOrWhiteSpace(errMsg)) result = result + "<br/>报警信息：" + errMsg;
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(parentErrMsg) && parentErrEndTime is null)
                    {
                        result = result + "<br/>设备状态：报警中";
                        if (!string.IsNullOrWhiteSpace(parentErrMsg)) result = result + "<br/>报警信息：" + parentErrMsg;
                    }
                    else
                    {
                        result = result + "<br/>设备状态：可用";
                    }
                }


            }
            else
            {
                result = result + "<br/>设备状态：不可用";
            }


        }


        if (boxType == (int)EnumScadaBoxType.CuringRow)
        {
            result = result + "硫化机排名称：" + boxName;

            if (ditchUseFlag == 1)
            {
                if (ditchUseFlag is not null && ditchUseFlag == 0)
                    result = result + "<br/>设备状态：不可用";
                else
                    result = result + "<br/>设备状态：可用";
            }
            else
            {
                result = result + "<br/>设备状态：不可用";
            }
        }

        if (emptyCount is not null && emptyCount >= 0)
        {
            result = result + "<br/>空库位数量：" + emptyCount;
        }

        return result;
    }

    /// <summary>
    /// 用来判断时间是否超期
    /// </summary>
    /// <param name="cmdCreateTime"></param>
    /// <param name="cmdMaxTime"></param>
    /// <returns></returns>
    public static bool GetIsTimeOutResult(DateTime? cmdCreateTime, int? cmdMaxTime)
    {
        var result = false;
        DateTime startTime = cmdCreateTime is null ? DateTime.Now : (DateTime)cmdCreateTime;

        DateTime dateTime = DateTime.Now;
        TimeSpan ts = dateTime.Subtract(startTime);

        var timeSlot = ts.TotalMinutes;

        if (cmdMaxTime is not null && timeSlot >= cmdMaxTime)
        {
            result = true;
        }

        return result;
    }


    /// <summary>
    /// 获取style
    /// </summary>
    /// <param name="taskNo"></param>
    /// <param name="showType"></param>
    /// <param name="showColor"></param>
    /// <param name="boxType"></param>
    /// <param name="useFlag"></param>
    /// <returns></returns>
    public static string GetStyles(int? taskNo, string errMsg, DateTime? errEndTime, int? ditchUserFlag, string showType, DateTime? cmdCreateTime,
                                    int? errorTaskNo, int? cmdMaxTime, string showColor, int? boxType, int? equipEnable, int? parentEquipEnable)
    {
        var result = $"fillColor={showColor};shape={showType};fontSize=25";

        if (taskNo is not null && taskNo > 0) result = $"fillColor=#009100;shape={showType};fontSize=25";//有胎

        if (GetIsTimeOutResult(cmdCreateTime, cmdMaxTime)) result = $"fillColor=#d8c717;shape={showType};fontSize=25";//超时

        if (boxType == (int)EnumScadaBoxType.Scanner && errorTaskNo is not null && errorTaskNo != 0) result = $"fillColor=#e56e62;shape={showType};fontSize=25";//角度扫描失败

        if (boxType == (int)EnumScadaBoxType.CuringRow && ditchUserFlag is not null && ditchUserFlag == 0) result = $"fillColor=#f43308;shape={showType};fontSize=25";//硫化机排禁用

        if (errMsg is not null && errEndTime is null) result = $"fillColor=#f43308;shape={showType};fontSize=25";//报警

        if (boxType != (int)EnumScadaBoxType.CuringRow && equipEnable is not null && equipEnable == 0) result = $"fillColor=#f43308;shape={showType};fontSize=25";//设备禁用

        return result;
    }

    /// <summary>
    /// 获取设备的style
    /// </summary>
    /// <param name="taskNo"></param>
    /// <param name="showType"></param>
    /// <param name="showColor"></param>
    /// <param name="boxType"></param>
    /// <param name="useFlag"></param>
    /// <returns></returns>
    public static string GetEquipStyles(int? cmdType, int? cmdStatus, string errMsg, DateTime? errEndTime, string parentErrMsg, DateTime? parentErrEndTime,
                        string showType, DateTime? cmdCreateTime, int? cmdMaxTime, string showColor, int? boxType, int? equipEnable, int? parentEquipEnable)
    {

        var result = $"fillColor={showColor};shape={showType};fontSize=25";

        if (cmdType is not null && cmdStatus is not null && cmdStatus == (int)EnumTaskCmdStatus.Executed
        && (cmdType == (int)EnumTaskType.Warehousing || cmdType == (int)EnumTaskType.Exwarehouse
            || cmdType == (int)EnumTaskType.EMS || cmdType == (int)EnumTaskType.Abnormal))
            result = $"fillColor=#009100;shape={showType};fontSize=25";//有胎

        if (GetIsTimeOutResult(cmdCreateTime, cmdMaxTime)) result = $"fillColor=#d8c717;shape={showType};fontSize=25";//超时

        if ((boxType == (int)EnumScadaBoxType.CrnFolk || boxType == (int)EnumScadaBoxType.EMS) && !string.IsNullOrWhiteSpace(parentErrMsg) && parentErrEndTime is null) result = $"fillColor=#f43308;shape={showType};fontSize=25";//父节点警告

        if ((boxType == (int)EnumScadaBoxType.CrnFolk || boxType == (int)EnumScadaBoxType.EMS) && !string.IsNullOrWhiteSpace(errMsg) && errEndTime is null) result = $"fillColor=#f43308;shape={showType};fontSize=25";//警告

        if ((boxType == (int)EnumScadaBoxType.CrnFolk || boxType == (int)EnumScadaBoxType.EMS) && parentEquipEnable is not null && parentEquipEnable == 0) result = $"fillColor=#f43308;shape={showType};fontSize=25";//父节点禁用

        if (equipEnable is not null && equipEnable == 0) result = $"fillColor=#f43308;shape={showType};fontSize=25";//设备禁用
                                                                                                                    //XLog.Log(new Log { Data = $"showName = {showName},cmdType = {cmdType},cmdStatus = {cmdStatus}, errCode = {errCode},parentErrCode = {parentErrCode},parentEnable = {parentEquipEnable},result = {result} <br/>" });
        return result;
    }


    public static string GetStyleV2(LineStyleParam param)
    {
        //00FFFF
        var result = $"fillColor={param.ShowColor};shape={param.ShowType};fontSize=25";

        if (GetIsTimeOutResult(param.CmdCreateTime, param.CmdMaxTime)) result = $"fillColor=#d8c717;shape={param.ShowType};fontSize=25";//超时

        if (param.BoxType == (int)EnumScadaBoxType.Scanner && param.ErrorTaskNo is not null && param.ErrorTaskNo != 0) result = $"fillColor=#e56e62;shape={param.ShowType};fontSize=25";//角度扫描失败

        if (param.BoxType == (int)EnumScadaBoxType.CuringRow && param.DitchUseFlag is not null && param.DitchUseFlag == 0) result = $"fillColor=#f43308;shape={param.ShowType};fontSize=25";//硫化机排禁用


        if (param.BoxType != (int)EnumScadaBoxType.CuringRow && param.EquipEnable is not null && param.EquipEnable == 0) result = $"fillColor=#f43308;shape={param.ShowType};fontSize=25";//设备禁用

        if (param.BoxType == (int)EnumScadaBoxType.Lines)
        {
            if (param.TaskNo is not null && param.TaskNo != 0)
            {
                //有任务号且有目的地
                if (!String.IsNullOrEmpty(param.TargetLocName))
                {
                    if (param.StartTaskType is not null && param.StartTaskType == 1)
                    {
                        result = $"fillColor=#53E420;shape={param.ShowType};fontSize=25";//有胎
                    }
                    else if (param.StartTaskType is not null && param.StartTaskType == 2  && !param.TargetLocName.Contains("异常"))
                    {
                        result = $"fillColor=#0000FF;shape={param.ShowType};fontSize=25";//有胎
                    }
                    else if (param.StartTaskType is not null && param.StartTaskType == 0  && param.TargetLocName.Contains("异常"))
                    {
                        result = $"fillColor=#00FFFF;shape={param.ShowType};fontSize=25";//有胎
                    }
                }
                else    //有任务号无目的地(未找到任务)
                {
                    if (param.LineSign == 1)//ab库中间线体 显示绿色
                    {
                        result = $"fillColor=#53E420;shape={param.ShowType};fontSize=25";//有胎
                    }
                    else//不是ab库中间的线体 报警
                    {
                        result = $"fillColor=#FF0000;shape={param.ShowType};fontSize=25";//有胎
                    }
                }
            }
        }
        else
        {
            if (param.TaskNo is not null && param.TaskNo != 0)
            {
                if (param.StartTaskType is not null && param.StartTaskType == 1)
                {
                    result = $"fillColor=#53E420;shape={param.ShowType};fontSize=25";//有胎
                }
                else if (param.StartTaskType is not null && param.StartTaskType == 2 && !param.TargetLocName.Contains("异常"))
                {
                    result = $"fillColor=#0000FF;shape={param.ShowType};fontSize=25";//有胎
                }
                else if (param.StartTaskType is not null && param.StartTaskType == 0 && param.TargetLocName.Contains("异常"))
                {
                    result = $"fillColor=#00FFFF;shape={param.ShowType};fontSize=25";//有胎
                }
            }
        }

        if (param.ErrMsg is not null && param.ErrEndTime is null) result = $"fillColor=#f43308;shape={param.ShowType};fontSize=25";//报警
        if (param.ErrMsg is not null && param.ErrEndTime is null && param.ErrMsg.Contains("设备状态:手动")) result = $"fillColor=#808080;shape={param.ShowType};fontSize=28";//手动

        if (param.BoxType == (int)EnumScadaBoxType.Building)
        {
            var color = param.EquipStatus == 0 ? "Cornsilk" : "#f43308";
            result = $"fillColor={color}";
        }

        return result;
    }

    public static string GetEquipStyleV2(LineStyleParam param)
    {
        var result = $"fillColor={param.ShowColor};shape={param.ShowType};fontSize=25";

        if (param.CmdType is not null && param.CmdStatus is not null && param.CmdStatus == (int)EnumTaskCmdStatus.Executed
        && (param.CmdType == (int)EnumTaskType.Warehousing || param.CmdType == (int)EnumTaskType.Exwarehouse
            || param.CmdType == (int)EnumTaskType.Abnormal))
            result = $"fillColor=#009100;shape={param.ShowType};fontSize=25";//有胎

        if (param.CmdType is not null && param.CmdStatus is not null && param.CmdStatus == (int)EnumTaskCmdStatus.Executed
        && param.CmdType == (int)EnumTaskType.EMS) result = $"fillColor=#0000FF;shape={param.ShowType};fontSize=25";//有胎


        if (GetIsTimeOutResult(param.CmdCreateTime, param.CmdMaxTime)) result = $"fillColor=#d8c717;shape={param.ShowType};fontSize=21";//超时

        if ((param.BoxType == (int)EnumScadaBoxType.CrnFolk || param.BoxType == (int)EnumScadaBoxType.EMS) && !string.IsNullOrWhiteSpace(param.ParentErrMsg) && param.ParentErrEndTime is null && !param.ParentErrMsg.Contains("手动")) result = $"fillColor=#f43308;shape={param.ShowType};fontSize=25";//父节点警告

        if ((param.BoxType == (int)EnumScadaBoxType.CrnFolk || param.BoxType == (int)EnumScadaBoxType.EMS) && !string.IsNullOrWhiteSpace(param.ErrMsg) && param.ErrEndTime is null & !param.ErrMsg.Contains("设备状态: 手动")) result = $"fillColor=#f43308;shape={param.ShowType};fontSize=25";//警告

        if ((param.BoxType == (int)EnumScadaBoxType.CrnFolk || param.BoxType == (int)EnumScadaBoxType.EMS) && param.ParentEquipEnable is not null && param.ParentEquipEnable == 0) result = $"fillColor=#f43308;shape={param.ShowType};fontSize=25";//父节点禁用

        if (param.BoxType == (int)EnumScadaBoxType.EMS && !string.IsNullOrWhiteSpace(param.ErrMsg) && param.ErrEndTime is null && param.ErrMsg.Contains("设备状态: 手动")) result = $"fillColor=#a6a6a6;shape={param.ShowType};fontSize=25";//手动

        if (param.EquipEnable is not null && param.EquipEnable == 0) result = $"fillColor=#f43308;shape={param.ShowType};fontSize=25";//设备禁用

        //XLog.Log(new Log { Data = $"showName = {showName},cmdType = {cmdType},cmdStatus = {cmdStatus}, errCode = {errCode},parentErrCode = {parentErrCode},parentEnable = {parentEquipEnable},result = {result} <br/>" });
        return result;
    }



    public static string GetCuringStyle(LineStyleParam param, List<CuringMessageBeans> curingNoOrders, List<CuringMessageBeans> curingOrders)
    {
        var result = "";

        if (param.BoxType == (int)EnumScadaBoxType.ScadaReceivePlatForm || param.BoxType == (int)EnumScadaBoxType.ScadaArm)
        {
            if (param.BoxName == "Y")
            {
                result = $"fillColor=#53E420;shape={param.ShowType};fontSize=25;Color=white;";
            }
            else
            {
                result = $"fillColor=white;shape={param.ShowType};fontSize=25;";
            }
        }
        else if (param.BoxType == (int)EnumScadaBoxType.ScadaCuring)
        {
            result = $"fillColor=GhostWhite;shape={param.ShowType};fontSize=25";//0{param.ShowColor}
            ////WriteLog($"进入硫化机模块111,{param.EquipId},{result}", true);

            try
            {

                if (param.RcvFlag == "Y")
                {
                    //WriteLog($"进入硫化机模块112,{param.EquipId},{result}", true);
                    result = $"fillColor=#FFFFFF;shape={param.ShowType};fontSize=25";
                }

                ////WriteLog($"进入硫化机模块222,{param.EquipId},{result}", true);
                //如果没有订单 
                if (curingNoOrders is not null && curingNoOrders.Count > 0)
                {
                    if (param.RcvFlag == "Y")
                    {
                        //WriteLog($"进入硫化机模块399aaa,{param.EquipId},{result}", true);
                        result = $"fillColor=#FFFFFF;shape={param.ShowType};fontSize=25";
                    }
                    else
                    {
                        //未请料 暂不处理
                        //WriteLog($"进入硫化机模块344,{param.EquipId},{result}", true);
                        result = $"fillColor=#BFBFBF;shape={param.ShowType};fontSize=25";
                    }
                }

                else
                {
                    //WriteLog($"进入硫化机模块355,{param.EquipId},{result},{param.ToJson()}", true);
                    var curingOrder = curingOrders.Where(t => t.TaskNo > 0).FirstOrDefault();
                    //WriteLog($"进入硫化机模块366,{param.EquipId},{result}", true);
                    if (curingOrder is not null)
                    {
                        ////WriteLog($"进入硫化机模块377,{param.EquipId},{result}", true);
                        result = $"fillColor=#53E420;shape={param.ShowType};fontSize=25";//有任务

                        var time = 0 - Convert.ToDouble(param.CmdMaxTime);

                        if (DateTime.Now.AddMinutes(time) > curingOrder.CmdTime)
                        {
                            ////WriteLog($"进入硫化机模块378,{param.EquipId},{result}", true);
                            result = $"fillColor=#FF9800;shape={param.ShowType};fontSize=25";//超时
                        }
                        //WriteLog($"进入硫化机模块399,{param.EquipId},{result}", true);

                    }
                    else
                    {
                        //if (param.RcvFlag == "Y")
                        //{
                        //    //WriteLog($"进入硫化机模块399aaa,{param.EquipId},{result}", true);
                        //    result = $"fillColor=#FFFFFF;shape={param.ShowType};fontSize=25";
                        //}
                        //else
                        //{
                        //WriteLog($"进入硫化机模块399aaa,{param.EquipId},{result}", true);
                        result = $"fillColor=#FFFF00;shape={param.ShowType};fontSize=25";//没有任务
                        //}
                        //WriteLog($"进入硫化机模块400,{param.EquipId},{result}", true);
                        var notaskCuringOrder = curingOrders.FirstOrDefault();

                        //BMaterialManageImpl curingMaterialCount = new BMaterialManageImpl();

                        StockMaterialCountPara curingMatial = new StockMaterialCountPara();

                        curingMatial.materialCode = param.tcmSpec;

                        if (notaskCuringOrder is not null)
                        {
                            var remark = notaskCuringOrder.SummaryReamrk;
                            if (!String.IsNullOrWhiteSpace(remark) && remark.Contains("库存不足"))
                            {

                                //WriteLog($"进入硫化机模块411,{param.EquipId},{result},{param.ToJson()}", true);

                                result = $"fillColor=#FF0000;shape={param.ShowType};fontSize=25";//库存不足

                                var curingMatialAndCount = GetStockMaterialCountList(curingMatial);
                                var MatialCount = curingMatialAndCount.Count;
                                if (MatialCount > 0)
                                {
                                    result = $"fillColor=#00FFFF;shape={param.ShowType};fontSize=25";//库存不足
                                }
                            }
                            if (!String.IsNullOrWhiteSpace(remark) && remark.Contains("满足出库货位") && remark.Contains("不一致"))
                            {
                                result = $"fillColor=#00FFFF;shape={param.ShowType};fontSize=25";//库存不足
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //WriteLog($"监控异常,{ex.ToString()}", true);
            }


            //if ((param.ShowCode ?? 0) == 1)
            //{
            //    //WriteLog($"进入硫化机模块111,{param.EquipId}", true);
            //    result = $"fillColor=#a50021;shape={param.ShowType};fontSize=25";//送完胎
            //}

            //if ((param?.SpecCount ?? 0) == 0 && !string.IsNullOrWhiteSpace(param?.tcmSpec)) result = $"fillColor=#e56e62;shape={param.ShowType};fontSize=25";//硫化物料不足

            //if (param.TaskNo is not null && param.TaskNo > 0)
            //{
            //    //WriteLog($"进入硫化机模块222,{param.EquipId}", true);
            //    result = $"fillColor=#009100;shape={param.ShowType};fontSize=25";//有任务
            //}

            //if (GetIsTimeOutResult(param.CmdCreateTime, param.CmdMaxTime))
            //{
            //    //WriteLog($"进入硫化机模块333,{param.EquipId}", true);
            //    result = $"fillColor=#d8c717;shape={param.ShowType};fontSize=25";//超时
            //}

            if (param.BoxName == "X")
            {
                ////WriteLog($"进入硫化机模块444,{param.EquipId}", true);
                result = $"fillColor=#818181;shape={param.ShowType};fontSize=25";//硫化机禁用
            }
        }
        return result;
    }

    /// <summary>
    /// 获取鼠标悬停的结果
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    public static string GetMouseOverResultV2(LineMouseOverParam param)
    {

        string result = "";



        if (param.BoxType is null)
        {
            return result;
        }



        if (param.TaskNo is not null && param.TaskNo > 0)
        {

            result = result + "任务号：" + param.TaskNo;

            if (!string.IsNullOrWhiteSpace(param.ProductCode))
            {
                result = result + "<br/>条码：" + param.ProductCode;
            }

            switch (param.CmdType)
            {
                case (int)EnumTaskType.Abnormal:
                    result = result + "<br/>任务类型：异常任务";
                    break;
                case (int)EnumTaskType.EMS:
                    result = result + "<br/>任务类型：EMS任务";
                    break;
                case (int)EnumTaskType.Exwarehouse:
                    result = result + "<br/>任务类型：出库任务";
                    break;
                case (int)EnumTaskType.Rotate:
                    result = result + "<br/>任务类型：旋转任务";
                    break;
                case (int)EnumTaskType.Transportation:
                    result = result + "<br/>任务类型：输送任务";
                    break;
                case (int)EnumTaskType.Warehousing:
                    result = result + "<br/>任务类型：入库任务";
                    break;
            }

            if (!string.IsNullOrWhiteSpace(param.TargetLocName))
            {
                result = result + "<br/>去向：" + param.TargetLocName;
            }

            if (!string.IsNullOrWhiteSpace(param.TaskRemarkMemo))
            {
                result = result + "<br/>说明：" + param.TaskRemarkMemo;
            }
        }




        if (param.BoxType == (int)EnumScadaBoxType.Lines)
        {
            if (param.TaskNo is not null && param.TaskNo > 0)
            {
                result = result + "<br/>线体编号：" + param.ShowName;
            }
            else
            {
                result = result + "线体编号：" + param.ShowName;
            }

            if (!string.IsNullOrWhiteSpace(param.ErrMsg) && param.ErrEndTime is null)
            {
                result = result + "<br/>线体状态：报警中";
                if (!string.IsNullOrWhiteSpace(param.ErrMsg)) result = result + "<br/>报警信息：" + param.ErrMsg;
            }
        }



        if (param.BoxType != (int)EnumScadaBoxType.Lines && param.BoxType != (int)EnumScadaBoxType.Description && param.BoxType != (int)EnumScadaBoxType.CuringRow)
        {
            if (param.BoxType == (int)EnumScadaBoxType.CrnFolk
                || param.BoxType == (int)EnumScadaBoxType.EMS
                || param.BoxType == (int)EnumScadaBoxType.Crn)
            {
                if (param.TaskNo is not null && param.TaskNo > 0)
                    result = result + "<br/>设备：" + param.ShowName;
                else
                    result = result + "设备：" + param.ShowName;


            }
            else
            {
                if (param.TaskNo is not null && param.TaskNo > 0)
                    result = result + "<br/>设备：" + param.BoxName;
                else
                    result = result + "设备：" + param.BoxName;
            }


            if (param.EquipEnable == 1)
            {
                if (param.ParentEquipEnable is not null && param.ParentEquipEnable == 0)
                    result = result + "<br/>设备状态：不可用";
                else
                    if (!string.IsNullOrWhiteSpace(param.ErrMsg) && param.ErrEndTime is null)
                {
                    result = result + "<br/>设备状态：报警中";
                    if (!string.IsNullOrWhiteSpace(param.ErrMsg)) result = result + "<br/>报警信息：" + param.ErrMsg;
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(param.ParentErrMsg) && param.ParentErrEndTime is null)
                    {
                        result = result + "<br/>设备状态：报警中";
                        if (!string.IsNullOrWhiteSpace(param.ParentErrMsg)) result = result + "<br/>报警信息：" + param.ParentErrMsg;
                    }
                    else
                    {
                        result = result + "<br/>设备状态：可用";
                    }
                }


            }
            else
            {
                result = result + "<br/>设备状态：不可用";
            }


        }


        if (param.BoxType == (int)EnumScadaBoxType.CuringRow)
        {
            result = result + "硫化机排名称：" + param.ShowName;


            if (param.DitchUseFlag is not null && param.DitchUseFlag == 1)
                result = result + "<br/>设备状态：可用";
            else
                result = result + "<br/>设备状态：不可用";

        }

        if (param.BoxType == (int)EnumScadaBoxType.Crn)
        {
            result = param.EmptyCount is not null ? (result + "<br/>可用库位数量：" + param.EmptyCount) : (result + "<br/>可用库位数量：0");

        }

        if (param.BoxType == (int)EnumScadaBoxType.Building)
        {

            ////WriteLog("<br/>提升机名称：" + param.BoxName, true);
            ////WriteLog("<br/>生产规格：" + param.EquipMaterial, true);
            ////WriteLog("<br/>提升机状态：" + param.EquipStatus, true);
            ////WriteLog("<br/>" + param.ReamrkMemo, true);

            var equipStatus = param.EquipStatus == 0 ? "开启" : "关闭";
            result = "提升机名称：" + param.ShowName
             + "<br/>生产规格：" + param.EquipMaterial
             + "<br/>提升机状态：" + equipStatus
             + "<br/>" + param.ReamrkMemo;

        }


        return result;
    }
    #endregion


    #region 硫化机部分
    public List<CuringMessageBeans> GetCuringMessageBeans(CuringMessageParam param)
    {
        var db = Db.Default;

        var scada = db.ScadaBoxs.Where(f => f.BoxLeft == param.X && f.BoxTop == param.Y).FirstOrDefault();
        if (scada is null)
        {
            return new List<CuringMessageBeans>();
        }
        if (scada.BoxType == (int)EnumScadaBoxType.CuringRow)
        {
            var list1 = Task.Run(() => GetNoSummaryCuringMessage(scada));//获取没有任务的节点
            var list2 = Task.Run(() => GetHaveSummaryCuringMessage(scada));//获取有任务的节点

            var list = list1.Result.Union(list2.Result).OrderBy(f => f.CuringCode).ThenBy(f => f.LeftRightFlag).ToList();
            return list;
        }

        else
        {
            return new List<CuringMessageBeans>();
        }

    }


    public CuringListBeans GetCuringListBeans(CuringListParam param)
    {
        var db = Db.Default;


        return null;
    }


    /// <summary>
    /// 有订单的部分
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    public List<CuringMessageBeans> GetHaveSummaryCuringMessage(POScadaBox scada)
    {
        var db = Db.Default;

        var curingDitch = db.RcsEquipCuringDitchs.Where(f => f.Id == scada.EquipId).AsEnumerable().ToList();
        if (curingDitch is null)
        {
            return new List<CuringMessageBeans>();
        }
        var query = db.RcsEquipCurings.AsEnumerable().ToList().Join(curingDitch, f => f.DitchId, s => s.Id, (f, s) => new
        {
            Curing = f,
            Ditch = s,
            Indexs = f.CuringModeIndex,
            Signs = f.CuringSign,
        })
        .Join(db.WcsEquipLocs.AsEnumerable().ToList(), f => f.Curing.Id, s => s.EquipId, (f, s) => new
        {
            Curing = f.Curing,
            Indexs = f.Indexs,
            Signs = f.Signs,
            TargetLoc = s.LocId,
        })
        .Join(db.RcsEquips.Where(t => t.UseFlag == 1).AsEnumerable().ToList(), f => f.Curing.Id, s => s.Id, (f, s) => new
        {
            Indexs = f.Indexs,
            Signs = f.Signs,
            Id = s.Id,
            CuringCode = s.EquipCode,
            UseFlag = s.EquipEnable,
            TargetLoc = f.TargetLoc,
            EquipId = s.Id,
        })
        .GroupJoin(db.WcsTasks.AsEnumerable().ToList(), f => f.EquipId, s => s.TargetEquip, (f, s) => new
        {
            Indexs = f.Indexs,
            Signs = f.Signs,
            Id = f.Id,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            TargetLoc = f.TargetLoc,
            Task = s
        })
        .SelectMany(f => f.Task.DefaultIfEmpty(), (f, s) => new
        {
            Indexs = f.Indexs,
            Signs = f.Signs,
            Id = f.Id,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            TaskNo = s?.TaskNo,
            TargetLoc = f.TargetLoc
        })
         .GroupJoin(db.WmsOutOrderSummarys.AsEnumerable().ToList(), f => f.TargetLoc, s => s.TargetLoc, (f, s) => new
         {
             Indexs = f.Indexs,
             Signs = f.Signs,
             Id = f.Id,
             CuringCode = f.CuringCode,
             UseFlag = f.UseFlag,
             TaskNo = f.TaskNo,
             Summary = s
         })
         .Where(f => f.Summary != null)
        .SelectMany(f => f.Summary.DefaultIfEmpty(), (f, s) => new CuringMessageBeans
        {
            Id = f.Id,
            TaskNo = f.TaskNo,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            Signs = f?.Signs ?? -1,
            Index = f?.Indexs ?? -1,
            LeftRightFlag = f == null && f.Signs == null ? null : f.Signs == 1 ? (f.Indexs == 1 ? "R" : "L") : (f.Indexs == 1 ? "L" : "R"),//左右膜
                                                                                                                                           //MouseOverResult = GetCuringMouseOverResult(f.CuringCode, s?.RemarkMemo, f.Indexs, f.Signs, s?.PlanCount, s?.RealCount, f.TaskNo, f.UseFlag),
                                                                                                                                           //Color = GetColor(f.UseFlag, s?.PlanCount, s?.RealCount, s?.RemarkMemo)
            MouseOverResult = GetCuringMouseOverResultV2(new CuringMouseOverParam
            {
                CuringCode = f.CuringCode,
                SummaryRemarkMemo = s?.RemarkMemo,
                Indexs = f.Indexs,
                Signs = f.Signs,
                PlanCount = s?.PlanCount,
                RealCount = s?.RealCount,
                TaskNo = f.TaskNo,
                UseFlag = f.UseFlag
            }),
            Color = GetColorV2(new CuringColorParam { PlanCount = s?.PlanCount, RealCount = s?.RealCount, UseFlag = f.UseFlag, SummaryRemarkMemo = s?.RemarkMemo })
        }).OrderBy(f => f.CuringCode).ToList();

        return query;
    }

    /// <summary>
    /// 没有订单的部分
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    public List<CuringMessageBeans> GetNoSummaryCuringMessage(POScadaBox scada)
    {
        var db = Db.Default;

        var curingDitch = db.RcsEquipCuringDitchs.Where(f => f.Id == scada.EquipId).AsEnumerable().ToList();
        if (curingDitch is null)
        {
            return new List<CuringMessageBeans>();
        }
        var query = db.RcsEquipCurings.AsEnumerable().ToList().Join(curingDitch, f => f.DitchId, s => s.Id, (f, s) => new
        {
            Curing = f,
            Ditch = s,
            Indexs = f.CuringModeIndex,
            Signs = f.CuringSign,
        })
        .Join(db.WcsEquipLocs.AsEnumerable().ToList(), f => f.Curing.Id, s => s.EquipId, (f, s) => new
        {
            f.Curing,
            f.Indexs,
            f.Signs,
            TargetLoc = s.LocId,
        })
        .Join(db.RcsEquips.Where(t => t.UseFlag == 1).AsEnumerable().ToList(), f => f.Curing.Id, s => s.Id, (f, s) => new
        {
            f.Indexs,
            f.Signs,
            s.Id,
            CuringCode = s.EquipCode,
            UseFlag = s.EquipEnable,
            f.TargetLoc,
            EquipId = s.Id,
        })
        .GroupJoin(db.WcsTasks.AsEnumerable().ToList(), f => f.EquipId, s => s.TargetEquip, (f, s) => new
        {
            f.Indexs,
            f.Signs,
            f.Id,
            f.CuringCode,
            f.UseFlag,
            f.TargetLoc,
            Task = s
        })
        .SelectMany(f => f.Task.DefaultIfEmpty(), (f, s) => new
        {
            f.Indexs,
            f.Signs,
            f.Id,
            f.CuringCode,
            f.UseFlag,
            s?.TaskNo,
            f.TargetLoc
        })
         .GroupJoin(db.WmsOutOrderSummarys.AsEnumerable().ToList(), f => f.TargetLoc, s => s.TargetLoc, (f, s) => new
         {
             f.Indexs,
             f.Signs,
             f.Id,
             f.CuringCode,
             f.UseFlag,
             f.TaskNo,
             Summary = s
         })
        .Where(f => f.Summary == null)
        .SelectMany(f => f.Summary.DefaultIfEmpty(), (f, s) => new CuringMessageBeans
        {
            Id = f.Id,
            TaskNo = f.TaskNo,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            Signs = f?.Signs ?? -1,
            Index = f?.Indexs ?? -1,
            LeftRightFlag = f == null && f.Signs == null ? null : f.Signs == 1 ? (f.Indexs == 1 ? "R" : "L") : (f.Indexs == 1 ? "L" : "R"),//左右膜
                                                                                                                                           //MouseOverResult = GetCuringMouseOverResult(f.CuringCode, f.Indexs, f.Signs, f.TaskNo, f.UseFlag),
                                                                                                                                           //Color = GetColor(f.UseFlag)
            MouseOverResult = GetCuringMouseOverResultV2(new CuringMouseOverParam { CuringCode = f.CuringCode, Indexs = f.Indexs, Signs = f.Signs, TaskNo = f.TaskNo, UseFlag = f.UseFlag }),
            Color = GetColorV2(new CuringColorParam { UseFlag = f.UseFlag })
        }).OrderBy(f => f.CuringCode).ToList();

        return query;
    }







    public static List<CuringMessageBeans> GetCuringNoOrderByCuringId(string curingCode)
    {
        var db = Db.Default;
        var query = db.RcsEquipCurings.
            Where(t => t.CuringCode == curingCode)
            .GroupJoin(db.WcsTasks, f => f.LocId, s => s.TargetLoc, (f, s) => new
            {

                f.Id,
                f.CuringCode,
                f.UseFlag,
                TargetLoc = f.LocId,
                Task = s,
                f.CuringDir,
            })
        .SelectMany(f => f.Task.DefaultIfEmpty(), (f, s) => new
        {

            f.Id,
            f.CuringCode,
            f.UseFlag,
            s.TaskNo,
            f.TargetLoc,
            f.CuringDir,
        }).GroupJoin(db.WmsOutOrderSummarys, f => f.TargetLoc, s => s.TargetLoc, (f, s) => new
        {
            f.CuringDir,
            f.Id,
            f.CuringCode,
            f.UseFlag,
            f.TaskNo,
            Summary = s,
        })

        .SelectMany(f => f.Summary.DefaultIfEmpty(), (f, s) => new
        {
            Id = f.Id,
            TaskNo = f.TaskNo,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            LeftRightFlag = f.CuringDir,
            Summary = s
        }).Where(t => t.Summary == null).Select(f => new CuringMessageBeans
        {
            Id = f.Id,
            TaskNo = f.TaskNo,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            LeftRightFlag = f.LeftRightFlag,
            //SummaryId = f.Summary.Id ?? 0,
            //SummaryReamrk = f.Summary.RemarkMemo,
            //CmdTime = f.Summary.CreateTime,
        }).OrderBy(f => f.CuringCode).ToList();

        return query;
    }

    public static List<CuringMessageBeans> GetCuringHaveOrderByCuringId(string curingCode)
    {
        var db = Db.Default;
        var query = db.RcsEquipCurings.
            Where(t => t.CuringCode == curingCode)
            .GroupJoin(db.WcsTasks, f => f.LocId, s => s.TargetLoc, (f, s) => new
            {

                f.Id,
                f.CuringCode,
                f.UseFlag,
                TargetLoc = f.LocId,
                Task = s,
                f.CuringDir,
            })
        .SelectMany(f => f.Task.DefaultIfEmpty(), (f, s) => new
        {

            f.Id,
            f.CuringCode,
            f.UseFlag,
            s.TaskNo,
            f.TargetLoc,
            f.CuringDir,
        }).Join(db.WcsTaskCmds, f => f.TaskNo, s => s.TaskNo, (f, s) => new
        {

            f.Id,
            f.CuringCode,
            f.UseFlag,
            f.TaskNo,
            f.TargetLoc,
            f.CuringDir,
            CmdTime = s.CreateTime,
        })
         .GroupJoin(db.WmsOutOrderSummarys, f => f.TargetLoc, s => s.TargetLoc, (f, s) => new
         {
             f.CuringDir,
             f.Id,
             f.CuringCode,
             f.UseFlag,
             f.TaskNo,
             f.CmdTime,
             Summary = s,
         })
        .SelectMany(f => f.Summary.DefaultIfEmpty(), (f, s) => new
        {
            Id = f.Id,
            TaskNo = f.TaskNo,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            LeftRightFlag = f.CuringDir,
            Summary = s,
            //SummaryId = f.Summary.FirstOrDefault().Id ?? 0,
            //SummaryReamrk = f.Summary.FirstOrDefault().RemarkMemo,
            //CmdTime = f.CmdTime,
            //MouseOverResult = GetCuringMouseOverResult(f.CuringCode, f.Indexs, f.Signs, f.TaskNo, f.UseFlag),
            //Color = GetColor(f.UseFlag)
            //MouseOverResult = GetCuringMouseOverResultV2(new CuringMouseOverParam { CuringCode = f.CuringCode, Indexs = f.Indexs, Signs = f.Signs, TaskNo = f.TaskNo, UseFlag = f.UseFlag }),
            //Color = GetColorV2(new CuringColorParam { UseFlag = f.UseFlag })
        }).Where(t => t.Summary != null).Select(f => new CuringMessageBeans
        {
            Id = f.Id,
            TaskNo = f.TaskNo,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            LeftRightFlag = f.LeftRightFlag,
            SummaryId = f.Summary.Id ?? 0,
            SummaryReamrk = f.Summary.RemarkMemo,
            CmdTime = f.Summary.CreateTime,
        }).OrderBy(f => f.CuringCode).ToList();

        return query;
    }


    public static List<CuringMessageBeans> GetAllCuringNoOrder()
    {
        var db = Db.Default;
        var query = db.RcsEquipCurings
            .GroupJoin(db.WcsTasks, f => f.LocId, s => s.TargetLoc, (f, s) => new
            {

                f.Id,
                f.CuringCode,
                f.UseFlag,
                TargetLoc = f.LocId,
                Task = s,
                f.CuringDir,
            })
        .SelectMany(f => f.Task.DefaultIfEmpty(), (f, s) => new
        {
            f.Id,
            f.CuringCode,
            f.UseFlag,
            s.TaskNo,
            f.TargetLoc,
            f.CuringDir,
        }).GroupJoin(db.WmsOutOrderSummarys, f => f.TargetLoc, s => s.TargetLoc, (f, s) => new
        {
            f.CuringDir,
            f.Id,
            f.CuringCode,
            f.UseFlag,
            f.TaskNo,
            Summary = s,
        })
        .SelectMany(f => f.Summary.DefaultIfEmpty(), (f, s) => new
        {
            Id = f.Id,
            TaskNo = f.TaskNo,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            LeftRightFlag = f.CuringDir,
            Summary = s
        }).Where(t => t.Summary == null).Select(f => new CuringMessageBeans
        {
            Id = f.Id,
            TaskNo = f.TaskNo,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            LeftRightFlag = f.LeftRightFlag,
            //SummaryId = f.Summary.Id ?? 0,
            //SummaryReamrk = f.Summary.RemarkMemo,
            //CmdTime = f.Summary.CreateTime,
        }).OrderBy(f => f.CuringCode).ToList();

        return query;
    }

    public static List<CuringMessageBeans> GetAllCuringHaveOrder()
    {
        var db = Db.Default;
        var query = db.RcsEquipCurings
            .GroupJoin(db.WcsTasks, f => f.LocId, s => s.TargetLoc, (f, s) => new
            {
                f.Id,
                f.CuringCode,
                f.UseFlag,
                TargetLoc = f.LocId,
                Task = s,
                f.CuringDir,
            })
        .SelectMany(f => f.Task.DefaultIfEmpty(), (f, s) => new
        {
            f.Id,
            f.CuringCode,
            f.UseFlag,
            s.TaskNo,
            s.SkuId,
            CmdTime = s.CreateTime,
            f.TargetLoc,
            f.CuringDir,
        }).GroupJoin(db.ProdSkus, f => f.SkuId, s => s.Id, (f, s) => new
        {

            f.Id,
            f.CuringCode,
            f.UseFlag,
            f.TaskNo,
            f.SkuId,
            f.CmdTime,
            f.TargetLoc,
            f.CuringDir,
            ProdSku = s,
        })
        .SelectMany(f => f.ProdSku.DefaultIfEmpty(), (f, s) => new
        {

            f.Id,
            f.CuringCode,
            f.UseFlag,
            f.TaskNo,
            f.CmdTime,
            f.TargetLoc,
            f.CuringDir,
            s.SkuCode,
        })

        //.Join(db.WcsTaskCmds, f => f.TaskNo, s => s.TaskNo, (f, s) => new
        //{

        //    f.Id,
        //    f.CuringCode,
        //    f.UseFlag,
        //    f.TaskNo,
        //    f.TargetLoc,
        //    f.CuringDir,
        //    CmdTime = s.CreateTime,
        //})
         .GroupJoin(db.WmsOutOrderSummarys, f => f.TargetLoc, s => s.TargetLoc, (f, s) => new
         {
             f.CuringDir,
             f.Id,
             f.CuringCode,
             f.UseFlag,
             f.TaskNo,
             f.CmdTime,
             f.SkuCode,
             Summary = s,
         })
        .SelectMany(f => f.Summary.DefaultIfEmpty(), (f, s) => new
        {
            Id = f.Id,
            TaskNo = f.TaskNo,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            LeftRightFlag = f.CuringDir,
            Summary = s,
            SkuCode = f.SkuCode,
        }).Where(t => t.Summary != null).Select(f => new CuringMessageBeans
        {
            Id = f.Id,
            TaskNo = f.TaskNo,
            CuringCode = f.CuringCode,
            UseFlag = f.UseFlag,
            LeftRightFlag = f.LeftRightFlag,
            SummaryId = f.Summary.Id ?? 0,
            SummaryReamrk = f.Summary.RemarkMemo,
            CmdTime = f.Summary.CreateTime,
            SkuCode = f.SkuCode,
        }).OrderBy(f => f.CuringCode).ToList();

        return query;
    }



    /// <summary>
    /// 获取鼠标悬停结果
    /// </summary>
    /// <param name="curingCode"></param>
    /// <param name="indexs"></param>
    /// <param name="signs"></param>
    /// <param name="planCount"></param>
    /// <param name="realCount"></param>
    /// <param name="taskNo"></param>
    /// <param name="useFlag"></param>
    /// <returns></returns>
    public static string GetCuringMouseOverResult(string curingCode, string summaryRemarkMemo, int? indexs, int? signs, int? planCount, int? realCount, int? taskNo, int? useFlag)
    {
        string result = "";
        if (!string.IsNullOrWhiteSpace(curingCode))
        {
            result = result + $"硫化机：{curingCode}";
        }

        // sign = 1 (index->1右， 2左)
        // sign = 2 (index->1左， 2右)
        if (signs is not null && signs == 1)
        {
            if (indexs is not null && indexs == 1)
            {
                result = result + $"<br/>左右膜：右膜";
            }
            else if (indexs is not null && indexs == 2)
            {
                result = result + $"<br/>左右膜：左膜";
            }

        }
        if (signs is not null && signs == 2)
        {
            if (indexs is not null && indexs == 1)
            {
                result = result + $"<br/>左右膜：左膜";
            }
            else if (indexs is not null && indexs == 2)
            {
                result = result + $"<br/>左右膜：右膜";
            }

        }

        if (planCount is not null && planCount == 1)
        {
            if (realCount is not null && realCount == 0)
            {
                result = result + $"<br/>请料状态：已请料";
                if (!string.IsNullOrWhiteSpace(summaryRemarkMemo))
                    result = result + $"<br/>无任务原因：{summaryRemarkMemo}";
            }
            else if (realCount is not null && realCount == 1)
            {
                result = result + $"<br/>请料状态：已创建出库任务";
            }
        }
        else
        {
            if (realCount is null || realCount == 0)
            {
                result = result + $"<br/>请料状态：未请料";
            }
        }

        if (taskNo is not null && taskNo > 0)
        {
            result = result + $"<br/>任务号：{taskNo}";
        }

        if (useFlag is not null && useFlag == 1)
        {
            result = result + $"<br/>设备状态：可用";
        }
        else if (useFlag is not null && useFlag == 0)
        {
            result = result + $"<br/>设备状态：不可用";
        }

        return result;
    }
    /// <summary>
    /// 获取鼠标悬停结果
    /// </summary>
    /// <param name="curingCode"></param>
    /// <param name="indexs"></param>
    /// <param name="realCount"></param>
    /// <param name="taskNo"></param>
    /// <param name="useFlag"></param>
    /// <returns></returns>
    public static string GetCuringMouseOverResult(string curingCode, int? indexs, int? signs, int? taskNo, int? useFlag)
    {
        string result = "";
        if (!string.IsNullOrWhiteSpace(curingCode))
        {
            result = result + $"硫化机：{curingCode}";
        }

        // sign = 1 (index->1右， 2左)
        // sign = 2 (index->1左， 2右)
        if (signs is not null && signs == 1)
        {
            if (indexs is not null && indexs == 1)
            {
                result = result + $"<br/>左右膜：右膜";
            }
            else if (indexs is not null && indexs == 2)
            {
                result = result + $"<br/>左右膜：左膜";
            }

        }
        if (signs is not null && signs == 2)
        {
            if (indexs is not null && indexs == 1)
            {
                result = result + $"<br/>左右膜：左膜";
            }
            else if (indexs is not null && indexs == 2)
            {
                result = result + $"<br/>左右膜：右膜";
            }

        }

        result = result + $"<br/>请料状态：未请料";


        if (taskNo is not null && taskNo > 0)
        {
            result = result + $"<br/>任务号：{taskNo}";
        }

        if (useFlag is not null && useFlag == 1)
        {
            result = result + $"<br/>设备状态：可用";
        }
        else if (useFlag is not null && useFlag == 0)
        {
            result = result + $"<br/>设备状态：不可用";
        }

        return result;
    }

    /// <summary>
    /// 获取颜色
    /// </summary>
    /// <param name="useFlag"></param>
    /// <param name="planCount"></param>
    /// <param name="realCount"></param>
    /// <returns></returns>
    public static string GetColor(int? useFlag, int? planCount, int? realCount, string summaryRemarkMemo)
    {
        string color = "GhostWhite";

        if (planCount is not null && planCount == 1)
        {
            if (realCount is not null && realCount == 0)
            {
                if (summaryRemarkMemo is not null && summaryRemarkMemo.Contains("库存不足")) color = "#ccff66";
                else color = "#8cc288";
            }
            else if (realCount is not null && realCount == 1)
            {
                color = "#009100";
            }
        }

        if (useFlag is not null && useFlag == 0)
        {
            color = "#f43308";
        }


        return color;
    }

    /// <summary>
    /// 获取颜色
    /// </summary>
    /// <param name="useFlag"></param>
    /// <returns></returns>
    public static string GetColor(int? useFlag)
    {
        string color = "GhostWhite";

        if (useFlag is not null && useFlag == 0)
        {
            color = "#f43308";
        }

        return color;
    }

    /// <summary>
    /// 获取鼠标悬停结果
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    public static string GetCuringMouseOverResultV2(CuringMouseOverParam param)
    {
        string result = "";
        if (!string.IsNullOrWhiteSpace(param.CuringCode))
        {
            result = result + $"硫化机：{param.CuringCode}";
        }

        // sign = 1 (index->1右， 2左)
        // sign = 2 (index->1左， 2右)
        if (param.Signs is not null && param.Signs == 1)
        {
            if (param.Indexs is not null && param.Indexs == 1)
            {
                result = result + $"<br/>左右膜：右膜";
            }
            else if (param.Indexs is not null && param.Indexs == 2)
            {
                result = result + $"<br/>左右膜：左膜";
            }

        }
        if (param.Signs is not null && param.Signs == 2)
        {
            if (param.Indexs is not null && param.Indexs == 1)
            {
                result = result + $"<br/>左右膜：左膜";
            }
            else if (param.Indexs is not null && param.Indexs == 2)
            {
                result = result + $"<br/>左右膜：右膜";
            }

        }

        if (param.PlanCount is not null && param.PlanCount == 1)
        {
            if (param.RealCount is not null && param.RealCount == 0)
            {
                result = result + $"<br/>请料状态：已请料";
                if (!string.IsNullOrWhiteSpace(param.SummaryRemarkMemo))
                    result = result + $"<br/>无任务原因：{param.SummaryRemarkMemo}";
            }
            else if (param.RealCount is not null && param.RealCount == 1)
            {
                result = result + $"<br/>请料状态：已创建出库任务";
            }
        }
        else
        {
            if (param.RealCount is null || param.RealCount == 0)
            {
                result = result + $"<br/>请料状态：未请料";
            }
        }

        if (param.TaskNo is not null && param.TaskNo > 0)
        {
            result = result + $"<br/>任务号：{param.TaskNo}";
        }

        if (param.UseFlag is not null && param.UseFlag == 1)
        {
            result = result + $"<br/>设备状态：可用";
        }
        else if (param.UseFlag is not null && param.UseFlag == 0)
        {
            result = result + $"<br/>设备状态：不可用";
        }

        return result;
    }

    /// <summary>
    /// 获取硫化机鼠标悬停的结果
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    public static string GetCuringMouseOverResult(LineMouseOverParam param, List<CuringMessageBeans> curingNoOrders, List<CuringMessageBeans> curingHaveOrders)
    {
        string result = "";

        //if (!String.IsNullOrWhiteSpace(result))

        //{
        //    result = result + $"<br>设备编号：{param?.BoxCode}" + $"<br>设备名：{param.ShowName}";
        //}
        //else
        //{
        result = result + $"设备名：{param.ShowName}<br>";
        //}






        if (param.BoxName == "X") result = result + "设备状态：停止使用<br>";
        //else if (GetIsTimeOutResult(param.CmdCreateTime, param.CmdMaxTime)) result = result + "设备状态：超时";
        //else if ((param.ShowCode ?? 0) == 1) result = result + "设备状态：已送胎";
        //else if (param.TaskNo > 0) result = result + "设备状态：正在送胎中";
        else
        {
            result = result + "设备状态：可用<br>";
        }

        if (!string.IsNullOrWhiteSpace(param.TcmSpec))
        {

            result = result + $"硫化物料：{param?.TcmSpec}<br>" + $"物料描述：{param?.TcmSpecDesc}<br> ";// + $"物料数量：{param?.SpecCount}";

            //if ((param?.SpecCount ?? 0) == 0)
            //{
            //    result = result + "<br>物料状态：库存不足";
            //}
        }
        else
        {

            result = result + $"硫化物料：MES未传递硫化物料<br>";
        }
        //判断是否有订单(没有订单)
        if (curingNoOrders.Count > 0)
        {
            if (curingNoOrders.Count >= 2)
            {
                //if (!String.IsNullOrWhiteSpace(result))
                //{
                //    result = result + "<br>";
                //}
                result = result + $"订单状态：未生成订单<br>";
            }
            else
            {
                var curingNoOrderL = curingNoOrders.Where(t => t.LeftRightFlag == "L").FirstOrDefault();
                if (curingNoOrderL is not null)
                {

                    result = result + $"订单状态：L：未生成订单，R：已生成订单<br>";
                }
                else
                {

                    result = result + $"订单状态：L：已生成订单，R：未生成订单<br>";
                }

            }
            //var curingNoOrders.Where(t => t.LeftRightFlag == "L").FirstOrDefault();
        }
        else
        {
            //判断任务
            var curingtaskOrders = curingHaveOrders.Where(t => t.TaskNo > 0).ToList();
            var curingtaskOrderL = curingtaskOrders.Where(t => t.LeftRightFlag == "L").FirstOrDefault();
            var curingtaskOrderR = curingtaskOrders.Where(t => t.LeftRightFlag == "R").FirstOrDefault();

            if (curingtaskOrders is not null && curingtaskOrders.Count > 0)
            {


                if (curingtaskOrderL is not null)
                {
                    result = result + "L - 任务号：" + curingtaskOrderL.TaskNo + "，L - 条码：" + curingtaskOrderL.SkuCode + "<br>";
                }
                else
                {
                    result = result + "L - 任务号：未创建 ，L - 条码：未创建<br>";
                }



                if (curingtaskOrderR is not null)
                {
                    result = result + "R - 任务号：" + curingtaskOrderR.TaskNo + "，R - 条码：" + curingtaskOrderR.SkuCode + "<br>";
                }
                else
                {
                    result = result + "R - 任务号：未创建 ，R - 条码：未创建<br>";
                }

            }
            else
            {
                result = result + "L-任务号：未创建 ，L-条码：未创建<br>";
                result = result + "R-任务号：未创建 ，R-条码：未创建<br>";
                var curingOrderL = curingHaveOrders.Where(t => t.LeftRightFlag == "L").FirstOrDefault();
                var curingOrderR = curingHaveOrders.Where(t => t.LeftRightFlag == "R").FirstOrDefault();
                if (curingOrderL is not null)
                {
                    result = result + "L-无订单原因：" + curingOrderL.SummaryReamrk + "<br>";
                }
                if (curingOrderR is not null)
                {
                    result = result + "R-无订单原因：" + curingOrderR.SummaryReamrk + "<br>";
                }


            }

            //if (!string.IsNullOrWhiteSpace(param.Remark))
            //{
            //    if (!String.IsNullOrWhiteSpace(result))
            //    {
            //        result = result + "<br>";
            //    }
            //    result = result + "未生成订单原因：" + param.Remark;
            //}
        }
        return result;
    }


    /// <summary>
    /// 获取颜色
    /// </summary>
    /// <param name="useFlag"></param>
    /// <param name="planCount"></param>
    /// <param name="realCount"></param>
    /// <returns></returns>
    public static string GetColorV2(CuringColorParam param)
    {
        string color = "GhostWhite";

        if (param.PlanCount is not null && param.PlanCount == 1)
        {
            if (param.RealCount is not null && param.RealCount == 0)
            {
                if (param.SummaryRemarkMemo is not null && param.SummaryRemarkMemo.Contains("库存不足")) color = "#ccff66";
                else color = "#8cc288";
            }
            else if (param.RealCount is not null && param.RealCount == 1)
            {
                color = "#009100";
            }
        }

        if (param.UseFlag is not null && param.UseFlag == 0)
        {
            color = "#f43308";
        }


        return color;
    }

    #endregion


    #region 堆垛机监控

    public List<CrnTaskBeans> GetCrnTask(CrnMonitorParam param)
    {
        if (string.IsNullOrWhiteSpace(param.CrnName)) param.CrnName = "1号堆垛机";
        var db = Db.Default;

        var CrnId = db.RcsEquips.Where(f => f.EquipName == param.CrnName).FirstOrDefault().Id;

        if (CrnId is null || CrnId < 0)
        {
            return new();
        }
        else
        {
            var forks = db.RcsEquipCrnToForks.Where(f => f.CrnEquipId == CrnId)
                        .Join(db.RcsEquips, f => f.FolkEquipId, s => s.Id, (f, s) => new { ForkName = s.EquipName, EquipId = s.Id });

            var product = db.ProdSkuProducts.Join(db.ProdProducts, f => f.ProductId, s => s.Id, (f, s) => new { Sku = f, Product = s })
                        .Join(db.ProdMaterials, f => f.Sku.MaterialId, s => s.Id, (f, s) => new { SkuId = f.Sku.SkuId, Product = f.Product, Material = s }).AsEnumerable();

            var taskCmdLoc = db.WcsTaskCmds.Where(f => (f.CmdType == 1 || f.CmdType == 2) && f.CmdStatus == (int)EnumTaskStatus.Executable)
                            .Join(db.WcsTasks, f => f.TaskId, s => s.Id, (f, s) => new { Tasks = s, Cmds = f, TaskNo = s.TaskNo })
                            .Join(db.RcsLocations, f => f.Cmds.StartLoc, s => s.Id, (f, s) => new { Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = s })
                            .Join(db.RcsLocations, f => f.Cmds.TargetLoc, s => s.Id, (f, s) => new { Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = f.StartLoc, TargetLoc = s })
                            .Join(db.RcsLocations, f => f.Tasks.TargetLoc, s => s.Id, (f, s) => new { Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = f.StartLoc, TargetLoc = f.TargetLoc, TaskTargetLoc = s })
                            .GroupJoin(db.RcsEquipCurings, f => f.Tasks.TargetEquip, s => s.Id, (f, s) => new { Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = f.StartLoc, TargetLoc = f.TargetLoc, TaskTargetLoc = f.TaskTargetLoc, Curing = s })
                            .SelectMany(f => f.Curing.DefaultIfEmpty(), (f, s) => new { Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = f.StartLoc, TargetLoc = f.TargetLoc, TaskTargetLoc = f.TaskTargetLoc, Curing = s })
                            .AsEnumerable();
            var query = forks.GroupJoin(taskCmdLoc, f => f.EquipId, s => s.Cmds.EquipId, (f, s) => new { Forks = f, TaskCmdLoc = s })
                            .SelectMany(f => f.TaskCmdLoc.DefaultIfEmpty(), (f, s) => new { Forks = f.Forks, Tasks = s.Tasks, Cmds = s.Cmds, StartLoc = s.StartLoc, TargetLoc = s.TargetLoc, TaskTargetLoc = s.TaskTargetLoc, Curing = s.Curing })
                            .GroupJoin(product, f => f.Tasks.SkuId, s => s.SkuId, (f, s) => new { Forks = f.Forks, Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = f.StartLoc, TargetLoc = f.TargetLoc, TaskTargetLoc = f.TaskTargetLoc, Curing = f.Curing, Product = s })
                            .SelectMany(f => f.Product.DefaultIfEmpty(), (f, s) => new CrnTaskBeans
                            {
                                CmdId = f.Cmds.Id,
                                TaskId = f.Tasks.Id,
                                ForkName = f.Forks.ForkName,
                                TaskNo = f.Tasks.TaskNo,
                                TaskType = GetTaskType(f.Tasks.TaskType),
                                TaskStatus = GetTaskStatus(f.Tasks.TaskStatus),
                                CreateTime = f.Tasks.CreateTime,
                                ExecTime = f.Tasks.UpdateTime,
                                TakeLoc = f.StartLoc.LocName,
                                PlaceLoc = f.TargetLoc.LocName,
                                TargetLoc = f.TaskTargetLoc.LocName,
                                ProductCode = s.Product.ProductCode,
                                Spec = s.Material.Spec,
                                Status = s.Product.GtStatus,
                                Frozen = !string.IsNullOrWhiteSpace(s.Product.ProductCode) ? s.Product != null && s.Product.Frozen == 1 ? "冻结" : "未冻结" : "",
                                CuringCode = f.Tasks.TaskType == 2 ? f.Curing.CuringCode : null,
                                LRFlag = f.Tasks.TaskType == 2 || f.Curing.CuringModeIndex == null || f.Curing.CuringSign == null ? null : f.Curing.CuringSign == 1 ? (f.Curing.CuringModeIndex == 1 ? "R" : "L") : (f.Curing.CuringModeIndex == 1 ? "L" : "R"),//左右膜
                            }).ToList();


            return query;
        }
    }

    public CrnEquipBeans GetCrnEquip(CrnMonitorParam param)
    {
        if (string.IsNullOrWhiteSpace(param.CrnName)) param.CrnName = "1号堆垛机";

        var db = Db.Default;

        var equip = db.RcsEquips.Where(f => f.EquipName == param.CrnName).FirstOrDefault();

        var equipErr = db.WmsEquipErrs.Where(f => f.EquipId == equip.Id && f.EndTime == null).OrderByDescending(f => f.CreateTime).FirstOrDefault();

        var taskCount = db.WcsTaskCmds.Where(f => f.EquipId == equip.Id && f.CmdStatus == (int)EnumTaskStatus.Executable).Count();

        var inLimit = db.WcsAsrsCrnInputs.Where(f => f.CrnId == equip.Id).FirstOrDefault()?.TaskCount;

        var outLimit = db.WcsAsrsCrnOutputs.Where(f => f.CrnId == equip.Id).FirstOrDefault()?.TaskCount;

        var Locs = db.WcsEquipLocHolds.Where(f => f.EquipId == equip.Id)
                    .Join(db.RcsLocations, f => f.LocId, s => s.Id, (f, s) => new { LocHold = f, Loc = s }).ToList();

        var allLocCount = Locs.GroupBy(f => new { f.LocHold.LocId }).Select(f => new { LocId = f.Key.LocId }).Count();

        var locNoEnableCount = Locs.Where(f => f.Loc.LocEnable == 0).GroupBy(f => new { f.LocHold.LocId }).Select(f => new { LocId = f.Key.LocId }).Count();

        var locHasSkuCount = Locs.Where(f => f.Loc.LocHasSku == 1).GroupBy(f => new { f.LocHold.LocId }).Select(f => new { LocId = f.Key.LocId }).Count();

        var locNoSkuCount = Locs.Where(f => f.Loc.LocHasSku == 0).GroupBy(f => new { f.LocHold.LocId }).Select(f => new { LocId = f.Key.LocId }).Count();

        CrnEquipBeans crnEquip = new()
        {
            CrnName = param.CrnName,
            CrnStatus = equip.EquipEnable is not null && equip.EquipEnable == 1 ? "启用" : "禁用",
            ErrStatus = equipErr?.ErrCode is not null && equipErr?.ErrCode > 0 ? "报警中" : "",
            ErrMsg = equipErr?.ErrMsg,
            TaskCount = taskCount,
            InLimit = inLimit,
            OutLimit = outLimit,
            LocNum = allLocCount,
            LocNoEnableNum = locNoEnableCount,
            EmptyNum = locNoSkuCount,
            NoEmptyNum = locHasSkuCount
        };

        return crnEquip;
    }

    #endregion

    #region EMS监控

    public List<EMSTaskBeans> GetEMSTasks(EmsMonitorParam param)
    {
        if (string.IsNullOrWhiteSpace(param.EmsName)) param.EmsName = "A排A号EMS小车";
        var db = Db.Default;

        var EmsId = db.RcsEquips.Where(f => f.EquipName == param.EmsName).FirstOrDefault().Id;

        if (EmsId is null || EmsId < 0)
        {
            return new();
        }
        else
        {
            var EMS = db.RcsEquips.Where(f => f.Id == EmsId);

            var product = db.ProdSkuProducts.Join(db.ProdProducts, f => f.ProductId, s => s.Id, (f, s) => new { Sku = f, Product = s })
                        .Join(db.ProdMaterials, f => f.Sku.MaterialId, s => s.Id, (f, s) => new { SkuId = f.Sku.SkuId, Product = f.Product, Material = s }).AsEnumerable();

            var taskCmdLoc = db.WcsTaskCmds.Where(f => f.CmdType == 5 && f.CmdStatus == (int)EnumTaskStatus.Executable)
                            .Join(db.WcsTasks, f => f.TaskId, s => s.Id, (f, s) => new { Tasks = s, Cmds = f, TaskNo = s.TaskNo })
                            .Join(db.RcsLocations, f => f.Cmds.StartLoc, s => s.Id, (f, s) => new { Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = s })
                            .Join(db.RcsLocations, f => f.Cmds.TargetLoc, s => s.Id, (f, s) => new { Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = f.StartLoc, TargetLoc = s })
                            .Join(db.RcsLocations, f => f.Tasks.TargetLoc, s => s.Id, (f, s) => new { Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = f.StartLoc, TargetLoc = f.TargetLoc, TaskTargetLoc = s })
                            .GroupJoin(db.RcsEquipCurings, f => f.Tasks.TargetEquip, s => s.Id, (f, s) => new { Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = f.StartLoc, TargetLoc = f.TargetLoc, TaskTargetLoc = f.TaskTargetLoc, Curing = s })
                            .SelectMany(f => f.Curing.DefaultIfEmpty(), (f, s) => new { Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = f.StartLoc, TargetLoc = f.TargetLoc, TaskTargetLoc = f.TaskTargetLoc, Curing = s })
                            .AsEnumerable();
            var query = EMS.GroupJoin(taskCmdLoc, f => f.Id, s => s.Cmds.EquipId, (f, s) => new { Ems = f, TaskCmdLoc = s })
                            .SelectMany(f => f.TaskCmdLoc.DefaultIfEmpty(), (f, s) => new { Ems = f.Ems, Tasks = s.Tasks, Cmds = s.Cmds, StartLoc = s.StartLoc, TargetLoc = s.TargetLoc, TaskTargetLoc = s.TaskTargetLoc, Curing = s.Curing })
                            .GroupJoin(product, f => f.Tasks.SkuId, s => s.SkuId, (f, s) => new { Ems = f.Ems, Tasks = f.Tasks, Cmds = f.Cmds, StartLoc = f.StartLoc, TargetLoc = f.TargetLoc, TaskTargetLoc = f.TaskTargetLoc, Curing = f.Curing, Product = s })
                            .SelectMany(f => f.Product.DefaultIfEmpty(), (f, s) => new EMSTaskBeans
                            {
                                CmdId = f.Cmds.Id,
                                TaskId = f.Tasks.Id,
                                EmsName = f.Ems.EquipName,
                                TaskNo = f.Tasks.TaskNo,
                                TaskStatus = GetTaskStatus(f.Tasks.TaskStatus),
                                TaskType = GetTaskType(f.Tasks.TaskType),
                                CreateTime = f.Tasks.CreateTime,
                                ExecTime = f.Tasks.UpdateTime,
                                TakeLoc = f.StartLoc.LocName,
                                PlaceLoc = f.TargetLoc.LocName,
                                TargetLoc = f.TaskTargetLoc.LocName,
                                ProductCode = s.Product.ProductCode,
                                Spec = s.Material.Spec,
                                Status = s.Product.GtStatus,
                                Frozen = !string.IsNullOrWhiteSpace(s.Product.ProductCode) ? s.Product != null && s.Product.Frozen == 1 ? "冻结" : "未冻结" : "",
                                CuringCode = f.Curing.CuringCode,
                                LRFlag = f.Curing.CuringModeIndex == null || f.Curing.CuringSign == null ? null : f.Curing.CuringSign == 1 ? (f.Curing.CuringModeIndex == 1 ? "R" : "L") : (f.Curing.CuringModeIndex == 1 ? "L" : "R"),//左右膜
                            }).ToList();


            return query;
        }
    }

    public EMSEquipBeans GetEMSEquip(EmsMonitorParam param)
    {
        if (string.IsNullOrWhiteSpace(param.EmsName)) param.EmsName = "A排A号EMS小车";

        var db = Db.Default;

        var equip = db.RcsEquips.Where(f => f.EquipName == param.EmsName).FirstOrDefault();


        var equipErr = db.WmsEquipErrs.Where(f => f.EquipId == equip.Id && f.EndTime == null).OrderByDescending(f => f.CreateTime).FirstOrDefault();

        var taskCount = db.WcsTaskCmds.Where(f => f.EquipId == equip.Id && f.CmdStatus == (int)EnumTaskStatus.Executable).Count();



        EMSEquipBeans crnEquip = new()
        {
            EmsName = param.EmsName,
            CrnStatus = equip.EquipEnable is not null && equip.EquipEnable == 1 ? "启用" : "禁用",
            ErrStatus = equipErr?.ErrCode is not null && equipErr?.ErrCode > 0 ? "报警中" : "",
            ErrMsg = equipErr?.ErrMsg,
            TaskCount = taskCount
        };

        return crnEquip;
        throw new NotImplementedException();
    }

    #endregion

    #region 指令重发
    public int ReSendCmds(long? cmdId)
    {
        var db = Db.Default;

        var result = db.WcsTaskCmds.Where(f => f.Id == cmdId).Update(new POWcsTaskCmd { CmdStatus = 0 });

        return db.SaveChanges();
    }
    #endregion

    #region 帮助方法
    /// <summary>
    /// 获取任务类型
    /// </summary>
    /// <param name="taskType"></param>
    /// <returns></returns>
    public static string GetTaskType(int? taskType)
    {
        if (taskType is not null && taskType > 0)
        {
            switch (taskType)
            {
                case (int)EnumTaskType.Abnormal:
                    return "异常任务";
                    break;
                case (int)EnumTaskType.EMS:
                    return "EMS任务";
                    break;
                case (int)EnumTaskType.Exwarehouse:
                    return "出库任务";
                    break;
                case (int)EnumTaskType.Rotate:
                    return "旋转任务";
                    break;
                case (int)EnumTaskType.Transportation:
                    return "输送任务";
                    break;
                case (int)EnumTaskType.Warehousing:
                    return "入库任务";
                    break;
                default:
                    return "";
            }
        }
        else return "";
    }

    /// <summary>
    /// 获取任务状态
    /// </summary>
    /// <param name="taskStatus"></param>
    /// <returns></returns>
    public static string GetTaskStatus(int? taskStatus)
    {
        if (taskStatus is not null && taskStatus > 0)
        {
            switch (taskStatus)
            {
                case (int)EnumTaskStatus.Create:
                    return "创建";
                    break;
                case (int)EnumTaskStatus.Executable:
                    return "可执行";
                    break;
                case (int)EnumTaskStatus.Executed:
                    return "已执行";
                    break;
                case (int)EnumTaskStatus.Finish:
                    return "任务完成";
                    break;
                default:
                    return "";
            }
        }
        else return "";
    }

    #endregion

    #region 库存状态显示图 —— 版本2


    public CrnLocBeans GetLocMonitorsByCrn(string crnName)
    {
        if (string.IsNullOrWhiteSpace(crnName))
        {
            crnName = "1号堆垛机";
        }
        //return null;

        return GetLocMonitorByCrn(crnName);

    }


    private CrnLocBeans GetLocMonitorByCrn(string crnName)
    {
        var db = Db.Default;

        var wmsSetting = _WmsSetting.GetWmsSettingByCode(ConstFields.ExWarehousingTime);
        _ = double.TryParse(wmsSetting?.Value, out var minute);

        var crnLocNodes = db.VCrnLocNode.Where(f => f.EquipName == crnName).Select(f => new
        {
            Color = GetLocColors(new CrnLocColorParam
            {
                LocEnable = f.LocEnable,
                LocHasSku = f.LocHasSku,
                MdTime = f.MdTime,
                SkuId = f.SkuId,
                TaskOccupy = f.TaskOccupy,
                ShowType = f.ShowType,
                TbmExpirationTime = f.TbmExpirationTime,
                TireLock = f.TireLock,
            }, minute),
            MouseOverResult = (f.ShowType != null && f.ShowType == 2) ? "" : GetLocMouseOverResult(new CrnLocOverResultParam
            {
                LocCode = f.LocCode,
                LocName = f.LocName,
                LocEnable = f.LocEnable,
                LocHasSku = f.LocHasSku,
                LocHasSkuTime = f.LocHasSkuTime,
                MdTime = f.MdTime,
                ProductCode = f.ProductCode,
                SkuId = f.SkuId,
                Spec = f.Spec,
                TaskOccupy = f.TaskOccupy,
                Remarks = f.Remarks,
                TbmExpirationTime = f.TbmExpirationTime,
                TireLock = f.TireLock,
            }, minute),
            WarehouseNo = f.WarehouseNo,
            LocRow = f.LocRow,
            LocColumn = f.LocColumn,
            Id = f.Id,
            Tip = GetLocTip(new CrnLocColorParam
            {
                LocEnable = f.LocEnable,
                LocHasSku = f.LocHasSku,
                MdTime = f.MdTime,
                SkuId = f.SkuId,
                TaskOccupy = f.TaskOccupy,
                ShowType = f.ShowType,
                TireLock = f.TireLock,
                TbmExpirationTime = f.TbmExpirationTime
            }, minute),
        }).ToList();

        var stock = crnLocNodes.Select(f => f.WarehouseNo).OrderBy(f => f).Distinct().ToList();

        var rows = crnLocNodes.Select(f => f.LocRow).OrderBy(f => f).Distinct().ToList();

        List<CrnLocNodes?> firstNodes = new List<CrnLocNodes?>();

        List<CrnLocNodes?> lastNodes = new List<CrnLocNodes?>();

        foreach (var no in stock)
        {
            foreach (var row in rows)
            {
                var columnNodes = crnLocNodes.Where(f => f.LocRow == row && f.WarehouseNo == no).ToList();
                CrnLocNodes? node = new();

                columnNodes.ForEach(node1 =>
                {
                    FlushLocNode(ref node, new FlushLocParam { LocId = node1.Id, Column = node1.LocColumn ?? 0, Color = node1.Color, MouseOverResult = node1.MouseOverResult, Tips = node1.Tip });
                });
                if (no == 1)//1#立库
                {
                    firstNodes.Add(node);
                }
                else if (no == 2)//2#立库
                {
                    lastNodes.Add(node);
                }

            }
        }


        return new CrnLocBeans { StockFirstNodes = firstNodes, StockLastNodes = lastNodes };
    }

    private static void FlushLocNode(ref CrnLocNodes node, FlushLocParam param)
    {
        switch (param.Column)
        {
            case 1:
                node.Node1 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 2:
                node.Node2 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 3:
                node.Node3 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 4:
                node.Node4 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 5:
                node.Node5 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 6:
                node.Node6 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 7:
                node.Node7 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 8:
                node.Node8 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 9:
                node.Node9 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 10:
                node.Node10 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 11:
                node.Node11 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 12:
                node.Node12 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 13:
                node.Node13 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 14:
                node.Node14 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 15:
                node.Node15 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 16:
                node.Node16 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 17:
                node.Node17 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 18:
                node.Node18 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 19:
                node.Node19 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 20:
                node.Node20 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 21:
                node.Node21 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 22:
                node.Node22 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 23:
                node.Node23 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 24:
                node.Node24 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 25:
                node.Node25 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 26:
                node.Node26 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 27:
                node.Node27 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 28:
                node.Node28 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 29:
                node.Node29 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 30:
                node.Node30 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 31:
                node.Node31 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 32:
                node.Node32 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 33:
                node.Node33 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 34:
                node.Node34 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 35:
                node.Node35 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 36:
                node.Node36 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 37:
                node.Node37 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 38:
                node.Node38 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 39:
                node.Node39 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;
            case 40:
                node.Node40 = new() { Tips = param.Tips, LocId = param.LocId, Color = param.Color, MouseOverResult = param.MouseOverResult };
                break;

            default:
                break;
        }
    }


    private static string GetLocTip(CrnLocColorParam param, double minute)
    {
        var color = "_";//默认无货

        if (param is null)
        {
            return color;
        }

        if (param.TaskOccupy is not null && param.TaskOccupy == 1)
        {
            color = "#";//任务占用
        }

        if (param.LocHasSku is not null && param.LocHasSku == 1)
        {
            color = "S";//有货
        }

        var outTime = DateTime.Now.AddMinutes(-minute);

        if (param.LocHasSku is not null && param.LocHasSku == 1 && param.TbmExpirationTime is not null && param.TbmExpirationTime < DateTime.Now)
        {
            color = "O";//超期
        }

        if (param.TireLock is not null && param.TireLock == 1)
        {
            color = "L";//锁定
        }
        //if (param.LocHasSku is not null && ((param.LocHasSku == 0 && param.SkuId is not null) || (param.LocHasSku == 1 && param.SkuId is null)))
        //{
        //    color = "e";//异常库位--有货无sku，无货有sku
        //}

        if (param.LocEnable is not null && param.LocEnable == 0)
        {
            color = "N";//库位禁用
        }

        return color;
    }

    private static string GetLocColors(CrnLocColorParam param, double minute)
    {
        var color = "#ffffff";//默认无货

        if (param is null)
        {
            return color;
        }

        if (param.TaskOccupy is not null && param.TaskOccupy == 1)
        {
            color = "#5b79e8";//任务占用
        }

        if (param.LocHasSku is not null && param.LocHasSku == 1)
        {
            color = "#569230";//有货
        }

        //var outTime = DateTime.Now.AddMinutes(-minute);
        if (param.LocHasSku is not null && param.LocHasSku == 1 && param.TbmExpirationTime is not null && param.TbmExpirationTime < DateTime.Now)
        {
            color = "#e0c431";//超期
        }

        //if(param.LocHasSku is not null && ((param.LocHasSku == 0 && param.SkuId is not null) || (param.LocHasSku == 1 && param.SkuId is null)))
        //{
        //    color = "#c7544d";//异常库位--有货无sku，无货有sku
        //}
        if (param.TireLock is not null && param.TireLock == 1)
        {
            color = "#808080";//锁定
        }

        if (param.LocEnable is not null && param.LocEnable == 0)
        {
            color = "#f70d0d";//库位禁用
        }

        return color;
    }

    private static string GetLocMouseOverResult(CrnLocOverResultParam param, double minute)
    {

        StringBuilder str = new();

        if (param is null)
        {
            return str.ToString();
        }



        if (!string.IsNullOrWhiteSpace(param.LocCode))
        {
            str.Append($"库位编号：{param.LocCode}<br/>");
        }

        if (!string.IsNullOrWhiteSpace(param.LocName))
        {
            str.Append($"库位名：{param.LocName}<br/>");
        }

        StringBuilder statusStr = new();

        if (param.LocHasSku is not null)
        {
            if (param.LocHasSku == 0)
            {
                statusStr.Append("无货");
            }
            else if (param.LocHasSku == 1)
            {
                statusStr.Append("有货");
            }
        }

        if (param.LocHasSku is not null && param.LocHasSku == 1 && param.TbmExpirationTime is not null && param.TbmExpirationTime < DateTime.Now)
        {
            statusStr.Append($"、库存超期");
        }

        if (param.TireLock is not null && param.TireLock == 1)
        {
            statusStr.Append($"、胎胚锁定");
        }

        if (param.TaskOccupy is not null && param.TaskOccupy == 1)
        {
            statusStr.Append($"、任务占用中");
        }

        //if(param.LocHasSku is not null && param.LocHasSku == 1 && param.SkuId is null)
        //{
        //    statusStr.Append($"、缺少Sku");
        //}

        if (param.LocEnable is not null && param.LocEnable == 0)
        {
            statusStr.Append($"、禁用中");
        }

        str.Append($"库位状态：{statusStr.ToString()}<br/>");

        if (param.LocHasSku is not null && param.LocHasSku == 1)
        {
            if (!string.IsNullOrWhiteSpace(param.ProductCode))
            {
                str.Append($"条码：{param.ProductCode}<br/>");
            }

            if (!string.IsNullOrWhiteSpace(param.Spec))
            {
                str.Append($"物料：{param.Spec}<br/>");
            }
            if (param.LocHasSkuTime is not null)
            {
                str.Append($"有货时间：{Convert.ToDateTime(param.LocHasSkuTime).ToString("yyyy-MM-dd HH:mm:ss.fff")}<br/>");
            }
        }

        if (param.LocEnable is not null && param.LocEnable == 0 && !string.IsNullOrWhiteSpace(param.Remarks))
        {
            str.Append($"禁用原因：{param.Remarks}<br/>");
        }

        return str.ToString();
    }

    #endregion

    public LineInfoBean GetLineInfoByLineId(long id)
    {
        var db = Db.Default;
        LineInfoBean result = new LineInfoBean();
        var lineEquip = db.VExceptEquipNodeV2.Where(t => t.EquipId == id).FirstOrDefault();
        if (lineEquip != null)
        {
            var data = db.WcsTasks.Join(db.WcsTaskCmds, f => f.Id, s => s.TaskId, (f, s) => new
            {

                TaskNo = f.TaskNo ?? 0,
                TaskGroup = f.TaskGroup ?? 0,
                TargetLoc = s.TargetLoc ?? 0,
            }).Join(db.RcsLocations, f => f.TargetLoc, s => s.Id, (f, s) => new
            {
                f.TaskNo,
                f.TaskGroup,
                s.PlcCode
            }).Join(db.ScadaBoxs, f => f.PlcCode, s => s.PlcCode, (f, s) => new
            {

                f.TaskNo,
                f.TaskGroup,
                s.BoxCode
            }).Where(t => t.TaskNo == lineEquip.TaskNo).FirstOrDefault();
            result.Id = lineEquip.EquipId;
            result.BoxCode = lineEquip.BoxCode;
            result.TaskNo = lineEquip.TaskNo;
            if (data is not null)
            {
                result.TargetCode = data.BoxCode;
                result.TaskGroup = data.TaskGroup;
            }
        }
        return result;
    }

    public int UpdateLineValue(UpdateLineInfoParam param)
    {
        //WriteLog($"开始进入修改线体值1,{param.ToJson()}", true);
        var db = Db.Default;
        var result = 0;
        try
        {
            var url = "http://172.17.130.128/:8411/api/k8/Equip/SetData";
            var nodes = db.ScadaBoxNodes.Where(t => t.BoxId == param.Id).ToList();
            //WriteLog($"开始进入修改线体值2,{nodes.ToJson()}", true);
            if (nodes is null || nodes.Count == 0)
            {
                //WriteLog($"开始进入修改线体值3", true);
                return result;
            }
            var taskNoId = nodes.Where(t => t.NodeName == "TaskNo").FirstOrDefault()?.NodeId ?? 0;
            var taskGroupId = nodes.Where(t => t.NodeName == "TaskGroup").FirstOrDefault()?.NodeId ?? 0;
            var targetCodeId = nodes.Where(t => t.NodeName == "TargetCode").FirstOrDefault()?.NodeId ?? 0;
            //WriteLog($"开始进入修改线体值4,{taskNoId}-{taskGroupId}-{targetCodeId}", true);
            List<lineValeData> lineDatas = new();
            if (taskNoId != 0 && !String.IsNullOrWhiteSpace(param?.TaskNo.ToString()))
            {
                //WriteLog($"开始进入修改线体值51", true);
                lineValeData data = new lineValeData()
                {
                    expireTime = 2000,
                    id = taskNoId,
                    value = param?.TaskNo.ToString(),
                };
                lineDatas.Add(data);

            }

            if (taskGroupId != 0 && !String.IsNullOrWhiteSpace(param?.TaskGroup.ToString()))
            {
                //WriteLog($"开始进入修改线体值52", true);
                lineValeData data = new lineValeData()
                {
                    expireTime = 2000,
                    id = taskGroupId,
                    value = param?.TaskGroup.ToString(),
                };
                lineDatas.Add(data);
            }
            if (targetCodeId != 0 && !String.IsNullOrWhiteSpace(param?.TargetCode))
            {
                //WriteLog($"开始进入修改线体值53", true);
                var lineCode = param?.TargetCode;
                var plcCode = "";
                if (param?.TargetCode == "0")
                {
                    plcCode = "0";
                }
                else
                {
                    plcCode = db.ScadaBoxs.Where(t => t.BoxCode == lineCode).FirstOrDefault()?.PlcCode;
                }
                if (!String.IsNullOrWhiteSpace(plcCode))
                {
                    lineValeData data = new lineValeData()
                    {

                        expireTime = 2000,
                        id = targetCodeId,
                        value = plcCode,
                    };
                    lineDatas.Add(data);
                }
            }

            //WriteLog($"开始进入修改线体值6", true);
            string jsonContent = lineDatas.ToJson();
            //WriteLog($"开始进入修改线体值7,{jsonContent}", true);
            PostData(url, jsonContent);
            //WriteLog($"开始进入修改线体值8", true);
            result = 1;
        }
        catch (Exception ex)
        {
            //WriteLog($"开始进入修改线体值异常{ex.ToString()}", true);

        }
        return result;
    }

    public static List<StockMaterialCount> GetStockMaterialCountList(StockMaterialCountPara parm)
    {
        var result = _ProdMaterial.GetStockMaterialCountList();
        if (!string.IsNullOrWhiteSpace(parm.materialCode))
        {
            result = result.Where(t => t.MaterialCode.Contains(parm.materialCode)).ToList();
        }
        return result;
    }


    public class lineValeData
    {
        public string value { get; set; }
        public int expireTime { get; set; }
        public long id { get; set; }

    }

    async Task PostData(string url, string jsonContent)
    {
        using var httpClient = new HttpClient();
        //url = "https://your-api-endpoint.com/post";
        //jsonContent = "{\"name\":\"John\",\"age\":30}";
        var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");

        HttpResponseMessage response = await httpClient.PostAsync(url, content);

        if (response.IsSuccessStatusCode)
        {
            string responseBody = await response.Content.ReadAsStringAsync();
            //WriteLog(responseBody, true);
            //return 1;
        }
        else
        {
            //return 0;
            //WriteLog("Error: " + response.StatusCode, true);
        }
    }



}

internal class CrnLocOverResultParam
{
    /// <summary>
    /// 库位编号
    /// </summary>
    public string LocCode { get; set; }
    /// <summary>
    /// 库位名
    /// </summary>
    public string LocName { get; set; }
    /// <summary>
    /// 条码
    /// </summary>
    public string ProductCode { get; set; }
    /// <summary>
    /// Spec码
    /// </summary>
    public string Spec { get; set; }
    /// <summary>
    /// 禁用备注
    /// </summary>
    public string Remarks { get; set; }
    /// <summary>
    /// 有货时间
    /// </summary>
    public DateTime? LocHasSkuTime { get; set; }

    /// <summary>
    /// 是否有货
    /// </summary>
    public int? LocHasSku { get; set; }
    /// <summary>
    /// 生产时间
    /// </summary>
    public DateTime? MdTime { get; set; }
    /// <summary>
    /// 任务占用
    /// </summary>
    public int? TaskOccupy { get; set; }
    /// <summary>
    /// 库位是否可用
    /// </summary>
    public int? LocEnable { get; set; }
    /// <summary>
    /// skuId
    /// </summary>
    public long? SkuId { get; set; }
    /// <summary>
    /// 超期时间
    /// </summary>
    public DateTime? TbmExpirationTime { get; set; }
    /// <summary>
    /// 是否锁定
    /// </summary>
    public int? TireLock { get; set; }
}

internal class FlushLocParam
{
    /// <summary>
    /// 列
    /// </summary>
    public int Column { get; set; }

    /// <summary>
    /// 颜色
    /// </summary>
    public string Color { get; set; }
    /// <summary>
    /// 鼠标悬浮展示
    /// </summary>
    public string MouseOverResult { get; set; }

    /// <summary>
    /// 库位Id
    /// </summary>
    public long? LocId { get; set; }
    /// <summary>
    /// 显示文字
    /// </summary>
    public string Tips { get; set; }
}
internal class CrnLocColorParam
{
    /// <summary>
    /// 是否有货
    /// </summary>
    public int? LocHasSku { get; set; }
    /// <summary>
    /// 生产时间
    /// </summary>
    public DateTime? MdTime { get; set; }
    /// <summary>
    /// 任务占用
    /// </summary>
    public int? TaskOccupy { get; set; }
    /// <summary>
    /// skuId
    /// </summary>
    public long? SkuId { get; set; }

    /// <summary>
    /// 库位是否可用
    /// </summary>
    public int? LocEnable { get; set; }
    /// <summary>
    /// 控件类型
    /// </summary>
    public int? ShowType { get; set; }

    public DateTime? TbmExpirationTime { get; set; }

    /// <summary>
    /// 是否锁定    /// </summary>
    public int? TireLock { get; set; }
}
public class CuringMouseOverParam
{
    /// <summary>
    /// 硫化机编号
    /// </summary>
    public string CuringCode { get; set; }

    /// <summary>
    /// 订单备注
    /// </summary>
    public string SummaryRemarkMemo { get; set; }

    public int? Indexs { get; set; }

    public int? Signs { get; set; }

    /// <summary>
    /// 计划数量
    /// </summary>
    public int? PlanCount { get; set; }

    /// <summary>
    /// 真实数量
    /// </summary>
    public int? RealCount { get; set; }

    /// <summary>
    /// 任务号
    /// </summary>
    public int? TaskNo { get; set; }

    /// <summary>
    /// 是否可用
    /// </summary>
    public int? UseFlag { get; set; }
}

public class CuringColorParam
{
    /// <summary>
    /// 是否可用
    /// </summary>
    public int? UseFlag { get; set; }

    /// <summary>
    /// 预计数量
    /// </summary>
    public int? PlanCount { get; set; }

    /// <summary>
    /// 真实数量
    /// </summary>
    public int? RealCount { get; set; }

    /// <summary>
    /// 订单备注
    /// </summary>
    public string SummaryRemarkMemo { get; set; }
}

public class LineStyleParam
{
    public int? TaskNo { get; set; }

    public string ErrMsg { get; set; }

    public DateTime? ErrEndTime { get; set; }


    public int? DitchUseFlag { get; set; }

    public string ShowType { get; set; }

    public DateTime? CmdCreateTime { get; set; }

    public int? ErrorTaskNo { get; set; }

    public int? CmdMaxTime { get; set; }

    public string ShowColor { get; set; }

    public int? BoxType { get; set; }

    public int? EquipEnable { get; set; }

    public int? ParentEquipEnable { get; set; }

    public int? CmdType { get; set; }

    public int? CmdStatus { get; set; }


    public string ParentErrMsg { get; set; }

    public DateTime? ParentErrEndTime { get; set; }


    public int? EquipStatus { get; set; }

    public int? StartTaskType { get; set; }

    public long? ShowCode { get; set; }

    public string BoxName { get; set; }


    public string tcmSpec { get; set; }
    public int? SpecCount { get; set; }

    public long? EquipId { get; set; }

    public string BoxCode { get; set; }

    public string TargetLocName { get; set; }

    public int? LineSign { get; set; }

    public string RcvFlag { get; set; }



}

public class LineMouseOverParam
{
    public int? BoxType { get; set; }

    public string TaskRemarkMemo { get; set; }

    public int? EmptyCount { get; set; }

    public int? DitchUseFlag { get; set; }

    public string ErrMsg { get; set; }

    public DateTime? ErrEndTime { get; set; }

    public string ParentErrMsg { get; set; }

    public DateTime? ParentErrEndTime { get; set; }

    public string TargetLocName { get; set; }

    public DateTime? CmdCreateTime { get; set; }

    public int? ErrorTaskNo { get; set; }

    public int? CmdMaxTime { get; set; }

    public int? TaskNo { get; set; }
    public int? TaskNo2 { get; set; }
    public int? CmdType { get; set; }

    public string ShowName { get; set; }

    public string BoxName { get; set; }

    public int? EquipEnable { get; set; }

    public int? ParentEquipEnable { get; set; }

    public string ProductCode { get; set; }

    public int? EquipStatus { get; set; }
    public string ReamrkMemo { get; set; }
    public string BuildingCode { get; set; }

    public string EquipMaterial { get; set; }


    public int? ShowCode { get; set; }

    public string TcmSpec { get; set; }
    public string TcmSpecDesc { get; set; }
    public string BoxCode { get; set; }
    public int? SpecCount { get; set; }
    public string Remark { get; set; }

}
public class SpecStock
{
    public string Spec { get; set; }

    public int Count { get; set; }
}


//public class BuildingMouseOverParam
//{
//    public int? BoxType { get; set; }


//    public string ShowName { get; set; }

//    public string BoxName { get; set; }

//    public int? EquipEnable { get; set; }

//    public int? EquipStatus { get; set; }
//    public string RemarkMemo { get; set; }
//    public string BuildingCode { get; set; }

//    public string EquipMaterial { get; set; }

//}